Reputation: 704
I noticed one of my buttons has a value for the background color = 'default'
When the button is highlighted I want to change a different button to also have a 'default' background color, here is my code so far:
@IBAction func buttonTouchUpInside(_ sender: UIButton) {
registerBtn.setTitleColor(UIColor.white, for: UIControlState.highlighted);
}
How do I achieve this so registerBtn has a background color which is basically transparent?
Upvotes: 8
Views: 18141
Reputation: 2415
Swift
button.backgroundColor = UIColor.clear
objective-C
button.backgroundColor = [UIColor clearColor];
Upvotes: 0
Reputation: 231
Use UIColor.clear
to make a color transparent.
It is very confusing that Apple calls it "default" instead of "clear."
Upvotes: 6
Reputation:
In the comments I found that:
(I'll edit the above as needed. Among the things I'm not entirely sure about is what should happen after when the first button is no longer highlighted.)
If the above is the situation, you need to do the following:
Probably the easiest way to do this is not through IB, but instead through code. After adding your buttons in IB, create IBOutlets for both of them. Then you can do this:
@IBOutlet weak var firstButton: UIButton!
@IBOutlet weak var secondButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
firstButton.addTarget(self, action: #selector(highlightSecondButton), for: .touchDown)
firstButton.addTarget(self, action: #selector(highlightSecondButton), for: .touchDragEnter)
}
func highlightSecondButton(_ sender:UIButton) {
secondButton.setTitleColor(UIColor.white, for: UIControlState.normal)
secondButton.backgroundColor = nil
}
Upvotes: 8