ios - UICollectionViewCell 不是圆角
问题描述
我试图使角落变圆,但是当我使用cornerRadius和maskToBouds时,它不起作用
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellId", for: indexPath)
cell.contentView.layer.cornerRadius = 30
cell.contentView.layer.masksToBounds = true
return cell
}
细胞:
解决方案
尝试在willDisplay:forItemAt:
例如
func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
cell.layer.cornerRadius = 30
cell.clipsToBounds = true
}
推荐阅读
- python - 此消息是否意味着我正确安装了 tensorflow GPU?
- c# - 正则表达式获取特定单词之前的所有单词
- android - 如何安装旧版本的 Google Play 服务?(SDK安卓)
- javascript - 从 React Native 中的错误对象获取堆栈数据 - Expo - CRNA
- php - PHP Prepared Statement vs mysqli_real_escape_string
- php - 完整日期模式正则表达式返回部分日期模式
- getelementsbyclassname - document.getElementsByClassName 困难
- powershell - 我需要在 PowerShell 中使用 $ 变量和某种比较
- java - 长按退格键时清除 EditText 的所有内容?
- c - 如何在 C 中编写基于 epoll 的套接字客户端