1

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!

FS.O6
  • 1,394
  • 2
  • 20
  • 42

1 Answers1

2

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).

Anton Belousov
  • 1,140
  • 15
  • 34