[英]How to set rounded corner for Uiimageview in Collectionview cell
我正在嘗試根據以下設計制作UICollectionviewCell
我已經為單元格設置了角半徑,但是當在collectonview
上加載數據時, imageview
沒有得到圓角。 我得到的輸出如下
圓角應用於單元格,但不應用於圖像。 這是我正在申請的代碼。 代碼應用於collectionView
( _ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
cell.layoutIfNeeded()
cell.layer.cornerRadius = 15
cell.imageView.clipsToBounds = true
cell.layer.masksToBounds = true
有人可以幫我解決這個問題。
提前致謝....
你需要設置imageView layer corner
半徑: -
cell.imageView.layer.cornerRadius = 15
cell.imageView.layer.masksToBounds = true
這樣做:
cell.contentView.layer.cornerRadius = 2.0
cell.contentView.layer.borderWidth = 1.0
cell.contentView.layer.borderColor = UIColor.clear.cgColor
cell.contentView.layer.masksToBounds = true;
這是如果你想為背景添加一個漂亮的陰影:
cell.layer.shadowColor = UIColor.lightGray.cgColor
cell.layer.shadowOffset = CGSize(width:0,height: 2.0)
cell.layer.shadowRadius = 2.0
cell.layer.shadowOpacity = 1.0
cell.layer.masksToBounds = false;
cell.layer.shadowPath = UIBezierPath(roundedRect:cell.bounds, cornerRadius:cell.contentView.layer.cornerRadius).cgPath
您還可以使用“用戶定義的運行時屬性”將角半徑設置為您的imageview Keypath - layer.cornerRadius類型 - 數字值 - 您的角半徑值
你可以說: cell.clipsToBounds = true
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.