ios - Swift - CollectionViewCell 边框错误或不完整

标签 ios swift xcode

我有一个看起来很奇怪的collectionViewCell。 左右垂直边框不见了,我不知道我错过了什么。 你们能帮我吗?谢谢!

 public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! profileServicesCell

    // Card border
    cell.backgroundColor = UIColor.white
    cell.layer.borderWidth = 1.0
    cell.layer.borderColor = UIColor.lightGray.cgColor

    // Cell Content
    cell.profileServiceName.text = profileServicesName[indexPath.row]
    cell.profileServiceIcon.image = UIImage(named: profileServicesIcon[indexPath.row])

    return cell
}

附图供引用:

Storyboard图像

StoryBoard Image

模拟器/运行时

enter image description here

最佳答案

可能是您没有为单元格指定任何大小的问题,请尝试一下:

extension Your_Class :  UICollectionViewDelegateFlowLayout {

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
    let width = self.view.frame.width * 0.4  // or whatever width you like 
    let height = width / 2 // or whatever height you like 
    return CGSize(width: width, height: height)
  }

   } 

关于ios - Swift - CollectionViewCell 边框错误或不完整,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51856615/

相关文章:

ios - DocuSign iOS 应用程序自定义 URL 方案?

ios - 将 RPPreviewController 中的视频保存到特定位置而不是保存到相机胶卷?

ios - 无法在现有的 Xcode 项目中安装 cocoaPods

swift - 如何使用 Realm Swift Init

ios - 如何定位 "unrecognized selector sent to instance"的错误在哪里?

ios - 使用 performSegueWithIdentifier() 向标识符添加撇号

ios - "dyld: Library not loaded"错误

ios - 通过在 textField Swift 中点击文本来识别文本

ios - 'ld : file not found' after changing product name in Xcode

iphone - 为什么我的委托(delegate)方法没有被调用?