FS.O6
FS.O6

Reputation: 1464

UIView corner radius is sharp on small screens

I have a button I'm setting its corner radius like this in ViewDidLoad():

self.myBtn.layer.cornerRadius = self.myBtn.frame.size.height / 2
self.myBtn.layer.masksToBounds = true

The result is great on the iPhone X. Screenshot:

X

But for some reason in devices that has smaller screens (like iPhone SE) the corners are really sharp and the result isn't what I want to achieve. Screenshot:

SE

Does anybody know why is it happening?

Thanks!

Upvotes: 1

Views: 695

Answers (1)

Anton Belousov
Anton Belousov

Reputation: 1141

Try to call your code in viewDidAppear (or better in viewDidLayoutSubviews)

It looks like you're using Autolayout. And it seems your button's layout depends on view's layout. The problem is: the size of viewController's view may be incorrect when viewDidLoad called (but it's corrected before viewDidAppear called).

Upvotes: 2

Related Questions