swift - UICollectionViewCell 不是 UITableView 内的圆角
问题描述
问题是当我在UICollectionView
里面UITableViewCell
时UICollectionViewCell
-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
}
解决方案
推荐阅读
- reactjs - React Hooks:切换模式下的重新渲染过多
- javascript - 带有 HTML 的 JS 加密
- php - 如何在远程 VPS 上运行 socketo.me 聊天服务器
- symfony - 如何在 JOIN 中添加多个“AND”条件
- python - 为什么我的模运算符为 1 字节的输入返回双倍的块大小?
- excel - 将关闭的工作簿中的值加载到数组中
- python - 在 Windows 挂钩中注入 dll 后出现无效的挂钩程序错误
- express - nginx conf express 和资产返回 404
- c - 如何用 C 语言编写一个程序,从文件中读取广告打印的特定行?
- python - 无法将 DICOM 的图像数据输入图像数据生成器