Swift corner radius proportions for all device types.

Hey. Hi. I assigned a corner radius of 30 to my uibutton with this code:

        startButton.layer.cornerRadius = 30

So far it looks very good on an iphone 13 pro max, but only there. So my question is: How can I create a corner radius that has the same proportions on all iphones? So looks good everywhere? (My button changes heigh depending on the heigh of the user's device:)

stackView1.heightAnchor.constraint(equalToConstant: height * 0.065).isActive = true

Can somebody help me with it? Greetings

I would do this:

  • save the height of the button (as for iPhone 13 pro max, probably defined in IB) in
var defautButtonHeight: CGFloat
  • then compute the radius:
startButton.layer.cornerRadius = 30 * startButton.bounds.height / defautButtonHeight
Swift corner radius proportions for all device types.
 
 
Q