How to make UILabel in Swift a circle

前端 未结 7 1162
孤街浪徒
孤街浪徒 2021-01-04 20:03

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 =          


        
7条回答
  •  隐瞒了意图╮
    2021-01-04 20:34

    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.

提交回复
热议问题