6

I have the following code in my didFinishLaunchingWithOptions function :

[[[UITableViewCell appearance] textLabel]setFont:[UIFont fontWithName:@"someFont" size:12]];

But for some reason this does not change the text in my table cells.

If in the table delegate function cellForRowAtIndexPath I add

cell.textLabel.font = [UIFont fontWithName:@"someFont" size:12];

It does change the font to my desired one.

Any ideas?

Ashley Mills
  • 50,474
  • 16
  • 129
  • 160
oopsi
  • 1,919
  • 3
  • 21
  • 28

1 Answers1

10

Setting the font property of a UITableViewCell is not supported using the appearance proxy.

You can tell which properties are supported by looking in the header file for that class for UI_APPEARANCE_SELECTOR.

Take a look at UITableViewCell.h and you'll see that only separatorInset is supported (and backgroundColor as this is supported by its superclass, UIView):

@property (nonatomic) UIEdgeInsets separatorInset NS_AVAILABLE_IOS(7_0) UI_APPEARANCE_SELECTOR; // allows customization of the separator frame


From the UIAppearance protocol reference:

To support appearance customization, a class must conform to the UIAppearanceContainer protocol and relevant accessor methods must be marked with UI_APPEARANCE_SELECTOR.

Ashley Mills
  • 50,474
  • 16
  • 129
  • 160
  • Why the down vote? This is the correct answer, but if you think it can be improved, please let me know how! – Ashley Mills Feb 26 '14 at 12:18
  • Thanks! But I'm looking now in the UITableViewCell.h and i can't see any UI_APPEARANCE_SELECTOR – oopsi Feb 26 '14 at 12:28
  • Hmm. I pasted code copied directly from `UITableViewCell.h` into my answer… does that help you locate it? – Ashley Mills Feb 26 '14 at 12:31
  • 1
    It's not that the Font property isn't supported, but a UITableViewCell doesn't have a Font. I think you're looking for the Font property on the UILabel. – Marcus Adams Feb 16 '16 at 16:25