首页 > 解决方案 > UICollectionViewCell 不是 UITableView 内的圆角

问题描述

问题是当我在UICollectionView里面UITableViewCellUICollectionViewCell-cornerRadius 功能不起作用。

代码非常简单,在玩UICollectionView.

extension ExploreTableViewCell: UICollectionViewDelegate, UICollectionViewDataSource {

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return 5
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! ExploreCollectionViewCell
    
    cell.thumbnail.layer.cornerRadius = 20
    cell.thumbnail.clipsToBounds = true
    
    return cell
}

这是一个错误还是什么?一整天都找不到答案。大多数人建议使用 contentView 而不是单元格内的特定图像,但这不适合我,因为我只想图像进行四舍五入。

PS这个有效(但我只想将单元格内的图像四舍五入):

    override func awakeFromNib() {
        super.awakeFromNib()
        self.layer.cornerRadius = 30
        self.clipsToBounds = true
    }

标签: swiftxcode

解决方案


推荐阅读