0

I want to change the tint color of a button.

  button.setTitle("✸", for: .normal)
  button.setTitleColor(.green, for: .normal)

This is working fine with the code above. However when I remove the first line (setTitle), it does not work anymore.

I have set a title for the button in the interfacebuilder/storyboard. I can't figure out what is the reason for that.


More research. Just one of these options work when the title is set via the interface builder. But when I change the title of the Button, option2 does not longer work.

    // option 1
    button.setTitle("✸", for: .normal)
    button.setTitleColor(.green, for: .normal)
    
    // option 2
    button.tintColor = .red
Vincent
  • 4,342
  • 1
  • 38
  • 37

1 Answers1

0

I want to change the tint color of a button.

So why don't you set the tintColor?

button.tintColor = .red

...this works even if you set the title only in the interface builder.

Suboptimierer
  • 554
  • 4
  • 11
  • tintColor is derived from the base class. When you change the title with setTitle, tintColor does not longer work – Vincent Sep 30 '22 at 07:09