I am trying to make a UICollectionviewCell
as per the following design
I have set corner radius for the cell, but when data is loaded on the collectonview
the imageview
is not getting rounded corners. The output that i am getting is as follows
Rounded corners are getting applied to the cells but not to the images. Here is the code that i am applying. The code is applied on collectionView
( _ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
cell.layoutIfNeeded()
cell.layer.cornerRadius = 15
cell.imageView.clipsToBounds = true
cell.layer.masksToBounds = true
Can someone help me to solve this issue.
Thanks in advance....
You need to set imageView layer corner
radius:-
cell.imageView.layer.cornerRadius = 15
cell.imageView.layer.masksToBounds = true
Just do this:
cell.contentView.layer.cornerRadius = 2.0
cell.contentView.layer.borderWidth = 1.0
cell.contentView.layer.borderColor = UIColor.clear.cgColor
cell.contentView.layer.masksToBounds = true;
This is if you want to add a nice shadow to the background:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.