Reputation: 27
The width(40) and height(40) of the UIView are equal.
I have tried these but they didn't work for me:
countView?.clipsToBounds = true
self.countView?.layer.cornerRadius = min((countView?.frame.size.width)!, (countView?.frame.size.height)!)/2
and also
self.countView.layer.cornerRadius = (countView.frame.size.width)/2
Thanks
Upvotes: 2
Views: 3138
Reputation: 2561
In addition to @Stephan answer.
With less code:
self.countView.layer.cornerRadius = self.countView.bounds.height / 2
Result:
Upvotes: 5
Reputation: 27106
You can use a mask layer like this:
override func viewDidLoad() {
super.viewDidLoad()
let maskLayer = CAShapeLayer()
maskLayer.path = UIBezierPath(ovalIn: self.countView.bounds).cgPath;
self.countView.layer.mask = maskLayer
}
Example Output
Here the output of a UIView with width/height = 128/128:
Upvotes: 2