gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 11:14:44 26 4
gpt4 key购买 nike

我有一个看起来很奇怪的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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com