Font color for UILabel not changing

12,477

Solution 1

Make sure your label's behavior like that. enter image description here

Solution 2

I encountered the same issue but it was cause by setting a custom color in the storyboard. Apparently you must have the color attribute set to default in order to change it programatically. I found this true with all UIViews.

Solution 3

I was trying change programtelly the textcolor of a UILabel in a UITabelViewCell in cellForRowAt. And the label just change the textcolor after being reloaded.

I could change the label textColor in the beggining after change the TEXTCOLOR IN STORYBOARD TO DEFAULT and i change it programatelly.

Share:
12,477

Related videos on Youtube

user220201
Author by

user220201

Updated on June 22, 2022

Comments

  • user220201
    user220201 almost 2 years

    I am trying to display numbers on a UILabel with a bold black font and size 50.

    After some failed attempts I just realized that no matter what color I set the font to, it always gets set to lightGray. Is there something else I need to do other than the below?

    [DisplayLabel setFont:[UIFont fontWithName:[NSString stringWithUTF8String:"HelveticaNeue-Bold"] size:50]];
    DisplayLabel.textColor = [UIColor brownColor];
    DisplayLabel.textAlignment = NSTextAlignmentCenter;
    

    I am adding the label using the storyboard to a view.

    • almas
      almas over 9 years
      Does the alignment and font change though when you do it programmatically?
    • user220201
      user220201 over 9 years
      The font size and alignment definitely change programmatically. Its just the color that does not change.
  • user220201
    user220201 over 9 years
    Where do I find this? I cannot find it.
  • user220201
    user220201 over 9 years
    Found it. I just enabled the label programmatically. Worked!
  • Pylinux
    Pylinux over 8 years
    @user220201 how did you activate it programmatically?
  • nsantorello
    nsantorello over 5 years
    Thank you, what an odd issue... I don't think I'd ever have figured this out on my own!
  • DroidT
    DroidT over 5 years
    No problem. Glad to save anyone the headache that I went through.
  • Peter Lapisu
    Peter Lapisu about 5 years
    i suppouse thats some kind of bug, not a feature
  • StephenFeather
    StephenFeather about 5 years
    Wow. I wasted so much time trying to get a label in a xib that we use over and over to change and it wouldn't. Thanks. Swift 4, Xcode Version 10.1 (10B61)
  • jaynp
    jaynp almost 5 years
    Running into the same bug. I believe it doesn't affect Attributed Text Labels