cornerRadius = (view.frame.size.height / 2.0)
Doesn't seem to work as expected. How to solve this? What might be the issue?
Output Screen-
cornerRadius = (view.frame.size.height / 2.0)
Doesn't seem to work as expected. How to solve this? What might be the issue?
Output Screen-
My solution in this case is you should put prepareUI
method in viewDidLayoutSubviews
. Try to add the code below.
override func viewDidLayoutSubviews() {
self.prepareUI();
}
I'm guessing that you want your corner radiuses to meet each other, and not have a straight line vertically between them? So that the sides of your red and green buttons meet up in a half circle?
Your view constraints aren't actually resolved until the viewDidLayoutSubviews()
function, so if your view changes during runtime because of the constraints you have set up, the frame you are calculating your corner radiuses from will change after viewDidLoad. If you use viewDidLayoutSubviews()
instead you should be fine:
override func viewDidLayoutSubviews() {
self.prepareUI();
}
you only need to set clipToBounds true for your View.
Example;
let view = UIView()
view.layer.cornerRadius = 14;
view.clipsToBounds = true;