How to make UILabel in Swift a circle

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

Circled corners or a full circle? Anyway, assuming that you want the second option, you should constraint the aspect ratio (width:height) to 1:1 on the storyboard so the label is always a square. Then, in the code, you can just do something like

pResult.layer.cornerRadius = pResult.frame.width/2

to always make it a perfect circle, no matter what screen size it will be on.

Tags:

Ios

Swift