15

What is the default font of the title of a UIBarButtonItem with a style of UIBarButtonItemStyleDone?

The following just returns nil:

[doneBarButtonItem titleTextAttributesForState:UIControlStateNormal]

ma11hew28
  • 121,420
  • 116
  • 450
  • 651

2 Answers2

13

[UIFont boldSystemFontOfSize:17]

Note: I confirmed this by doing:

UIFont *font = [UIFont boldSystemFontOfSize:17];
[doneBarButtonItem setTitleTextAttributes:@{NSFontAttributeName: font}
                                 forState:UIControlStateNormal];

And then, I took screenshots of the before & after and compared them. They were identical.

ma11hew28
  • 121,420
  • 116
  • 450
  • 651
  • 4
    This doesn't take into account iOS 7's Dynamic Type sizing information. – Ben S Sep 22 '13 at 16:58
  • Good point. Although, that doesn't appear to affect `UIBarButtonItem` title font. In any case, the slider in Settings > General > Text Size was directly in the middle upon precisely confirming this answer. – ma11hew28 Sep 22 '13 at 17:07
  • 2
    Plus this could change in the future (if it hasn't already). Not really an acceptable answer. There needs to be a way to get it programatically – MobileMon Apr 15 '15 at 20:08
  • Maybe it changed since 2013, but this is not true anymore. [UIFont systemFontOfSize:17] seems to be ok now (not sure I'm just comparing screenshots) – CedricSoubrie Nov 05 '15 at 10:22
13

You can retrieve the default font for a UILabel (which includes UIBarButton's title label) by querying

UIFont.systemFont(ofSize: UIFont.labelFontSize)
Luke Rogers
  • 2,369
  • 21
  • 28
Felix
  • 776
  • 8
  • 16