i am using round corner for my collection view cells, this is working fine in iPhone XS Max and XR, but round corner is not showing in others. below is the code which i am using.
class ButtonCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var buttonImage: UIImageView!
@IBOutlet weak var buttonTitle: UILabel!
@IBOutlet weak var cellBackGroundView: UIView!
@IBOutlet weak var imageWidthContraint: NSLayoutConstraint!
@IBOutlet weak var imageHeightContraint: NSLayoutConstraint!
override func awakeFromNib() {
super.awakeFromNib()
self.applyShadow(shadowColor: UIColor.gray, shadowRadious: 4, shadowOpacity: 1)
makeRoundedCorners()
}
func makeRoundedCorners() {
cellBackGroundView.roundCorners(corners: .allCorners, radius: 15)
}
func setupImageSize(cellType : String){
if cellType == "12" {
imageWidthContraint.constant = 40
imageHeightContraint.constant = 50
}else if cellType == "13"{
imageWidthContraint.constant = 62
imageHeightContraint.constant = 34
}
}
}
extension UIView {
func roundCorners(corners: UIRectCorner, radius: CGFloat) {
let path = UIBezierPath(roundedRect: bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
let mask = CAShapeLayer()
layer.mask = mask
mask.path = path.cgPath
}
}
You can try this
extension UIView {
func roundCorners(radius: CGFloat) {
self.layer.masksToBounds = true
self.layer.cornerRadius = radius
}
}