Font color for UILabel not changing
Solution 1
Make sure your label's behavior like that.
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 UIView
s.
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.
Related videos on Youtube
user220201
Updated on June 22, 2022Comments
-
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 over 9 yearsDoes the alignment and font change though when you do it programmatically?
-
user220201 over 9 yearsThe font size and alignment definitely change programmatically. Its just the color that does not change.
-
-
user220201 over 9 yearsWhere do I find this? I cannot find it.
-
user220201 over 9 yearsFound it. I just enabled the label programmatically. Worked!
-
Pylinux over 8 years@user220201 how did you activate it programmatically?
-
nsantorello over 5 yearsThank you, what an odd issue... I don't think I'd ever have figured this out on my own!
-
DroidT over 5 yearsNo problem. Glad to save anyone the headache that I went through.
-
Peter Lapisu about 5 yearsi suppouse thats some kind of bug, not a feature
-
StephenFeather about 5 yearsWow. 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 almost 5 yearsRunning into the same bug. I believe it doesn't affect Attributed Text Labels