我有一个看起来很奇怪的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图像
模拟器/运行时
最佳答案
可能是您没有为单元格指定任何大小的问题,请尝试一下:
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/