我有一个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图片
模拟器/运行时
答案 0 :(得分:0)
也许是您没有为单元格指定任何大小的问题,请尝试以下方法:
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)
}
}