[英]Swift - CollectionViewCell Border Bug or Incomplete
I have a collectionViewCell which appears to be weird. 我有一个collectionViewCell看起来很奇怪。 The left,right vertical borders are missing, I don't know what I'm missing. 左右两个垂直边框都丢失了,我不知道我要丢失什么。 Can you help me guys? 你能帮我吗? Thanks! 谢谢!
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
}
Attached images for reference : 所附图片供参考:
StoryBoard Image 故事板图像
Simulator/RunTime 模拟器/运行
maybe the problem that you didn't specify any size for your cell try this out : 也许您没有为单元格指定任何大小的问题可以尝试一下:
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)
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.