5

When my viewcontroller initially loads my font color doesnt change. But if I go to another viewcontroller and then go back to this viewcontroller my button font finally changes color. I've tried adding the code below to the viewwillappear and viewdidload:

self.SaveBTN.titleLabel!.textColor = UIColor.blueColor()

Any Idea as to why the font color only changes when i go to another view controller and then switch back but not on the initial first load of the page?

Flow of app:

Navigation Controller -> tab bar Controller -> view controller (button is here)
  • If you want to change the color of the actual button, why don't don't you use self.SaveBTN.view.backgroundColor() = UIColor.blueColor()? – Acoop Aug 02 '15 at 02:19
  • i want to change the font color not the background color –  Aug 02 '15 at 02:20
  • The first part of your question is unclear. I advise you edit it. – Acoop Aug 02 '15 at 02:22
  • I've edited my question, hopefully it's more clear now –  Aug 02 '15 at 02:25

1 Answers1

1

Use SaveBTN.setTitleColor(UIColor.blueColor(), forState: .Normal) in the viewDidLoad function.

Caleb
  • 5,548
  • 3
  • 25
  • 32
  • it works on the initial load now, thanks! any idea as to why my code above didn't work on the initial load? –  Aug 02 '15 at 02:32
  • Sorry, I'm not sure. Using setTitleColor is the correct convention. Someone suggested here: http://stackoverflow.com/questions/6703699/uibutton-title-text-color that the color reverts back to the original color set in the IB, but I do not know if that is the actual reason for this. Apple does not give any clear answer either. – Caleb Aug 02 '15 at 02:36