Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Font color for UILabel not changing

Tags:

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.

like image 493
user220201 Avatar asked Aug 18 '14 02:08

user220201


People also ask

How do I change the color of my UILabel Swift?

The easiest workaround is create dummy labels in IB, give them the text the color you like and set to hidden. You can then reference this color in your code to set your label to the desired color. The only way I could change the text color programmatically was by using the standard colors, UIColor.

How do I make my text bold on UILabel?

Write the following text in the label “Bold Regular”Double Click on Bold to select it, and then right click on it to see more options. Select font > Bold from that option. It should do the task.

How do I change the UILabel text in Swift?

To change the font or the size of a UILabel in a Storyboard or . XIB file, open it in the interface builder. Select the label and then open up the Attribute Inspector (CMD + Option + 5). Select the button on the font box and then you can change your text size or font.


2 Answers

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.

like image 106
DroidT Avatar answered Oct 20 '22 20:10

DroidT


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

like image 25
Madao Avatar answered Oct 20 '22 20:10

Madao