【问题标题】:remove border in UICollectionView when cells loaded from xib从 xib 加载单元格时删除 UICollectionView 中的边框
【发布时间】:2018-01-28 09:54:05
【问题描述】:

我有一个 collectionView,我的单元格是从 xib 加载的。

我正在尝试使用以下几行删除边框(我只想要阴影):

cell.contentView.layer.borderWidth = 1.0 //I also tried with 0.0
cell.contentView.layer.borderColor = UIColor.clear.cgColor
cell.contentView.layer.masksToBounds = true

但它似乎不起作用。

我尝试将这些行放在下一个函数中:

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell 

甚至在单元格类的函数awakeFromNib中。

知道如何删除边框吗?

【问题讨论】:

    标签: ios swift uitableview border xib


    【解决方案1】:

    您正在尝试的代码是 borderWidth 和边框颜色。

    使用下面的行作为阴影并删除上面的代码。

    cell.contentView.layer.masksToBounds = false
    cell.contentView.layer.shadowColor = UIColor.black.cgColor
    cell.contentView.layer.shadowOpacity = 0.5
    cell.contentView.layer.shadowOffset = CGSize(width: -1, height: 1)
    cell.contentView.layer.shadowRadius = 1
    
    cell.contentView.layer.shadowPath = UIBezierPath(rect: self.bounds).cgPath
    cell.contentView.layer.shouldRasterize = true
    
    cell.contentView.layer.rasterizationScale = UIScreen.main.scale
    

    【讨论】:

    • 谢谢!问题是 maskToBounds 标志。
    猜你喜欢
    • 2020-04-13
    • 1970-01-01
    • 2015-11-23
    • 2021-12-13
    • 1970-01-01
    • 1970-01-01
    • 2011-03-11
    • 1970-01-01
    相关资源
    最近更新 更多