I have 2 buttons. "Stocks" one is default, it has larger size and bold, the "Favorites" one is small. When the second one is pressed, I want "Stocks" to change size dynamically. I tried to hardcode, but then realized viewDidLoad() is called only once. How can I handle this?
//MARK: - Stocks Button and Favorites Button
stocksButton.setTitle("Stocks", for: .normal)
activated(button: stocksButton)
favoritesButton.setTitle("Favorites", for: .normal)
disabled(button: favoritesButton)
if favoritesButton.isSelected {
disabled(button: stocksButton)
activated(button: favoritesButton)
}
if (stocksButton.isSelected) {
disabled(button: favoritesButton)
activated(button: stocksButton)
}
func disabled(button: UIButton) {
button.setTitleColor(.gray, for: .normal)
button.titleLabel?.font = UIFont.systemFont(ofSize: 18)
}
func activated(button: UIButton) {
button.setTitleColor(.black, for: .normal)
button.titleLabel?.font = UIFont.systemFont(ofSize: 28)
}
// this is in my viewDidLoad() function
2
Answers
You will need to do this in the methods that get called when each button is pressed. So in the (for example)
stocksButtonPressed
you can setdisabled(button: favoritesButton)
and in thefavoritesButtonPressed
you can calldisabled(button: stocksButton)
.The is another way to do it. Declare your buttons, set constraints an use CGAffineTransform in UIview.animate:
This is the result