Why am I not able to change UIButton text-color?

Issue

Setting tintColor works only for buttonType = .custom. When you create a button using UIButton() the default buttonType would be .system which will override your global titleLabel and tintColor due to configuration with specific states

Solution

If you want the behavior of the system UIButton of fading the titleLabel when pressing the button, you need to set the titleColor for each state like below:

let button = UIButton()
button.setTitleColor(UIColor.red, for: .normal)

Otherwise you can use .custom and set tintColor directly.

let button = UIButton(type: .custom)
button.tintColor = UIColor.red

If you want to use the TintColor as the title Color, the type should be System instead of Custom


You can change its title directly like:

let button = UIButton()
button.titleLabel?.textColor = .red