Reputation: 3233
I have a UIButton that uses System icons as images, at the minute I am setting the tint colour using the following
buttonLogin?.tintColor = Globals().buttonFontColor
Now when I go to press the button the highlighted state changes the tint colour to a dark grey. I would like to change this so that when I press the button the colour can be set by me. I have tried subclassing the button with no luck.
import UIKit
class CustomButton: UIButton {
override open var isHighlighted: Bool {
didSet {
tintColor = isHighlighted ? UIColor.white : UIColor.green
}
}
/*
// Only override draw() if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func draw(_ rect: CGRect) {
// Drawing code
}
*/
}
Can someone point me in the right directions thanks.
Upvotes: 0
Views: 1187
Reputation: 760
You have to also disable adjusting image property:
buttonLogin?.adjustsImageWhenHighlighted = false
Now grey effect should be vanished
Upvotes: 1