Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

changing the text color of a UILabel

Tags:

ios

uilabel

Hi Im trying to change the text color of a UILabel in one of my views but having no luck.

Is there something quite obvious that Im not doing in this code?

self.nameTopRight.backgroundColor = [UIColor redColor]; self.nameBottomRight.textColor = [UIColor redColor]; 
like image 265
banditKing Avatar asked Aug 05 '11 04:08

banditKing


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 change text color in Xcode?

Xcode Getting started with Xcode Changing The Color SchemeWith the preference pane open you can click on the 'Fonts and Colors' tab. From here you can change the source AND console background and font colors.

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

The question was already answered for the OP, but for the sake of other people who come here trying to change a label's text color, use the textColor property:

Swift

myLabel.textColor = UIColor.red  // or .red 

Objective-C

myLabel.textColor = [UIColor redColor]; 
like image 120
Suragch Avatar answered Sep 29 '22 11:09

Suragch


They need to be connected in Interface Builder.

like image 31
cdasher Avatar answered Sep 29 '22 09:09

cdasher