How to make UILabel in Swift a circle

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

    Create UILabel extension

    extension UILabel {
        func addBadge(badgeCount: String) {
           self.text = badgeCount
            self.textColor = UIColor.white
            self.textAlignment = .center
            self.font = UIFont.systemFont(ofSize: 14.0)
           self.layer.cornerRadius = 0.5 * self.bounds.size.width
            self.layer.backgroundColor = UIColor.orange.cgColor
           
        }
    

提交回复
热议问题