UILabel subclass initialize with custom color

后端 未结 2 1466
时光取名叫无心
时光取名叫无心 2021-02-04 13:37

My goal is to set the textColor of my custom UILabel subclass in my view controller. I have a UILabel subclass named CircleLabel

2条回答
  •  孤独总比滥情好
    2021-02-04 13:55

    1. Custom Label In swift

        class CustomLabel: UILabel {
    
        @IBInspectable var topInset: CGFloat = 5.0
        @IBInspectable var bottomInset: CGFloat = 5.0
        @IBInspectable var leftInset: CGFloat = 7.0
        @IBInspectable var rightInset: CGFloat = 7.0
    
        override func drawText(in rect: CGRect) {
            let insets = UIEdgeInsets(top: topInset, left: leftInset, bottom: bottomInset, right: rightInset)
            super.drawText(in: rect.inset(by: insets))
        }
    
        override var intrinsicContentSize: CGSize {
            let size = super.intrinsicContentSize
            return CGSize(width: size.width + leftInset + rightInset,
                          height: size.height + topInset + bottomInset)
        }
    }
    

提交回复
热议问题