Prevent text color change in UILabel due to change of text color of fill text in swift

I am trying to make global color changes in an iOS app. I ran into a problem when changes to UILabel.appearance().textColorpropagate to UITextField placeholder text. The solutions I saw for this problem are related to setting attributed strings or digging into private members of UITextField. How to globally change the text color of UILabel text as well as placeholder text in a text box? I tried the code below, but in the end I got all the green text.

UILabel.appearance().textColor = UIColor.greenColor()

// UITextField placeholder color
UILabel.appearanceWhenContainedInInstancesOfClasses([UITextField.self]).textColor = UIColor.cyanColor()
+4
source share
1 answer

- UIAppearance. ( , UI_APPEARANCE_SELECTOR.) - UITextField; , Interface Builder.

@IBDesignable class PCTextField: UITextField {
    @IBInspectable var placeholderColor: UIColor = UIColor.redColor() {
        didSet {
            if let placeholder = self.placeholder {
                let colorAttribute = [NSForegroundColorAttributeName: placeholderColor]
                attributedPlaceholder = NSAttributedString(string: placeholder, attributes: colorAttribute)
            }
        }
    }
}

, placeholderColor NSUserDefaults UIAppearance.

+1

All Articles