The default text color for all UILabels

后端 未结 2 394
醉梦人生
醉梦人生 2021-02-05 18:07

I want to set the default text color for all UILabels in my app. I found this:

UILabel.appearance().textColor = UIColor.red

This works, but whe

2条回答
  •  再見小時候
    2021-02-05 18:43

    SubClass you labels with CustomLabel.swift. You can set text color using IBDesignable property named as txtColor

    Below is the code working example

    import UIKit
    
        @IBDesignable  class CustomLabel: UILabel {
    
            @IBInspectable var txtColor: UIColor = UIColor.grayColor() {
                didSet {
                    self.textColor = txtColor
                }
            }
    
            func setup() {
               self.textColor = txtColor
            }
    
            override func awakeFromNib() {
                setup()
            }
    
            override func prepareForInterfaceBuilder() {
                setup()
            }
    
        }
    

提交回复
热议问题