iOS 7: What is UIBarButtonItem's default font?
Asked Answered
V

2

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]

Vex answered 22/9, 2013 at 16:53 Comment(0)
V
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.

Vex answered 22/9, 2013 at 16:53 Comment(4)
This doesn't take into account iOS 7's Dynamic Type sizing information.Know
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.Vex
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 programaticallyOneiromancy
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)Croom
S
13

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

UIFont.systemFont(ofSize: UIFont.labelFontSize)
Schnauzer answered 3/6, 2016 at 8:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.