Xcode 12.5/iOS 13+/Swift 5
I've got multiple UIButton
s and I change their border color in their "Identity Inspector" with borderColor
set to the custom ColorSet
"ButtonBorderColor".
The button's text and background change properly when I switch to dark mode but the border doesn't. According to Stackexchange you have to override traitCollectionDidChange
like this:
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
if (traitCollection.hasDifferentColorAppearance(comparedTo: previousTraitCollection)) {
layer.borderColor = UIColor(named: "ButtonBorderColor")!.cgColor
}
}
But where do you put this, so it affects every button in my app? I tried to add it to an extension UIButton {}
, which told me to add open
to the function but the color doesn't change when I switch mode.