I am trying to make a UILabel in Swift a perfect circle. I am currently using the following:
pResult.layer.masksToBounds = true
pResult.layer.cornerRadius = 125
The problem with this is that it works fine on 6s plus but any other size it does not become a circle. What is the best way to do this?
I assume you're setting layer. cornerRadius in the user defined runtime attributes and are expecting the background color rectangle to have rounded corners? Check if you've enabled "Clip to Bounds" in the view drawing options, that's off by default for labels but is required for the rounded corners to work.
A view that displays one or more lines of informational text.
To make the text on UILabel underlined we will need to use the NSMutableAttributedString together with NSUnderlineStyleAttributeName. The Swift code snippet below demonstrates how to create a new UILabel programmatically and then use the NSMutableAttributedString to underline the text on the label.
If you you want to make perfect circle then first make sure your label width and height are same.
pResult.layer.cornerRadius = CGRectGetWidth(pResult.frame)/2
pResult.layer.masksToBounds = true
Reference
If you are using swift 3 then please try this:
lblRoundDot.layer.cornerRadius = lblRoundDot.frame.width/2
lblRoundDot.layer.masksToBounds = true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With