Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternatives to appearance proxy for Table Cells' UILabel setFont

I'm loving being able to use an appearance proxy in my iOS5 app to customise the NavigationController UI elements system-wide, however:

I have a lot of nested tables in my app, of which I'd love to be able to change the font across all table cells. They are mainly statically created. I've put some cell generation inside of a class, being read from an array, but the main issue lies with a large contents section I've tabled in Interface Builder. IB doesn't seem to have the option for mass-font setting.

I was wondering if anyone could help me find a way to set all the UITableCell fonts in one go?

Perhaps something like:

[[UILabel appearance] setFont:[UIFont fontWithName:@"Times" size:17.00];
like image 587
Sarreph Avatar asked Mar 21 '12 20:03

Sarreph


2 Answers

You can use appearanceWhenContainedIn: to narrow down which UIViews you'd like to set the appearance for.

In your example, try:

[[UILabel appearanceWhenContainedIn:[UITableViewCell class], nil] 
          setFont:[UIFont fontWithName:@"Times" size:17.00]];
like image 71
Mike Katz Avatar answered Nov 15 '22 00:11

Mike Katz


Actually, no. It is not valid to use UIAppearance to style a UILabel. See my self-answered question here. It kinda works, but it's not valid, for the reasons outlined over there.

like image 2
Joshua J. McKinnon Avatar answered Nov 15 '22 00:11

Joshua J. McKinnon