1
votes

I want to apply different corner radius value to different corners of UIView in iOS using swift. It means topLeft, topRight, bottomLeft, bottomRight corners of UIView should have different corner radiuous(i.e 1, 5, 10, 15). How can be implement it?

I tried applying cornerRadius in same way but It overrides the previous cornerRadius values.

1
You can also go through this tutorialImad Ali
@ReinierMelian Thanks. This what I was looking for. At least, I got gist from it.Ganesh Kakade

1 Answers

1
votes

If your deployment target is abouve iOS 10 then you should use maskedCorners

if #available(iOS 11.0, *) {
    customeView.clipsToBounds = true
    customeView.layer.cornerRadius = 5
    customeView.layer.maskedCorners = [.layerMaxXMaxYCorner, .layerMinXMaxYCorner, .layerMaxXMinYCorner, .layerMinXMinYCorner]
} 

else try this

let path = UIBezierPath(roundedRect: customeView.bounds, byRoundingCorners:[.bottomLeft, .bottomRight], cornerRadii: CGSize(width: 5, height: 5))
            let mask = CAShapeLayer()
            mask.path = path.cgPath
            customeView.layer.mask = mask