Font color for UILabel not changing
Asked Answered
T

5

24

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.

Tesch answered 18/8, 2014 at 2:47 Comment(2)
Does the alignment and font change though when you do it programmatically?Elissaelita
The font size and alignment definitely change programmatically. Its just the color that does not change.Tesch
I
25

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

Invasion answered 18/8, 2014 at 3:51 Comment(3)
Where do I find this? I cannot find it.Tesch
Found it. I just enabled the label programmatically. Worked!Tesch
@Tesch how did you activate it programmatically?Smollett
L
61

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.

Lilienthal answered 27/7, 2018 at 13:52 Comment(5)
Thank you, what an odd issue... I don't think I'd ever have figured this out on my own!Tallage
No problem. Glad to save anyone the headache that I went through.Lilienthal
i suppouse thats some kind of bug, not a featureHerculean
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)Phone
Running into the same bug. I believe it doesn't affect Attributed Text LabelsDessiatine
I
25

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

Invasion answered 18/8, 2014 at 3:51 Comment(3)
Where do I find this? I cannot find it.Tesch
Found it. I just enabled the label programmatically. Worked!Tesch
@Tesch how did you activate it programmatically?Smollett
O
2

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.

Opisthognathous answered 18/9, 2019 at 19:10 Comment(0)
D
0

Yeah, that bug is pretty annoying. Just relaunch the Xcode and it will work good

Durra answered 6/4, 2020 at 10:24 Comment(0)
M
-1

I got this to work for a table or collection view cell by setting the color first to a system color, then to my custom color in cellForRowAtIndexPath e.g.

myLabel.textColor = .black
myLabel.textColor = UIColor(named: "My custom color")
Morocco answered 2/11, 2019 at 11:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.