Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
283 views
in Technique[技术] by (71.8m points)

iphone - How do you change the color of a UIFont?

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!

question from:https://stackoverflow.com/questions/4585715/how-do-you-change-the-color-of-a-uifont

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...