除iPhone XS max和XR以外的所有模拟器均不能使用圆角

问题描述 投票:1回答:2

我在我的收藏夹视图单元格中使用圆角,这在iPhone XS Max和XR中工作正常,但在其他位置则不显示圆角。下面是我正在使用的代码。


 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

    }

    }
ios swift xcode uicollectionviewcell rounded-corners
2个回答
0
投票

使用类似的东西

cell.layer.cornerRadius = 10
cell.layer.masksToBounds = true

我认为您不需要f unc roundCorners(corners: UIRectCorner, radius: CGFloat)


0
投票

您可以尝试这个

extension UIView {

    func roundCorners(radius: CGFloat) {

        self.layer.masksToBounds = true
        self.layer.cornerRadius = radius
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.