How do you change the color of a UIFont?

CodeGuy picture CodeGuy · Jan 3, 2011 · Viewed 45.1k times · Source

I've searched the web and I can't get a good answer, although I'm sure this is very simple. Can someone please show me how to do the following: Make a UIFont of name "Helvetica-Bold", size 8.0, and color of black.

I've got the name and size, but I can't figure out how to change the color:

UIFont *textFont = [UIFont fontWithName:@"Helvetica-Bold" size:8.0];

Thanks!

Answer

theChrisKent picture theChrisKent · Jan 3, 2011

UIFont does not contain/maintain any color information, so this is not possible. In general, controls that use UIFont such as a UILabel have both a font and a textColor property. So you would set a label's font and it's color like this:

myLabel.textColor = [UIColor blackColor];
myLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:8.0];