How to make UILabel in Swift a circle

前端 未结 7 1151
孤街浪徒
孤街浪徒 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:35

    Depend on the answer of @FruitAddict, i would like to improve it more perfect. You should use .height property instead .width cause in case the length of label be longer (the text increase) this code won't working. And the code will be like this:

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

提交回复
热议问题