Skip to content

Instantly share code, notes, and snippets.

@Koze
Last active October 10, 2018 20:57
Show Gist options
  • Save Koze/46860386c93e44d9aba2 to your computer and use it in GitHub Desktop.
Save Koze/46860386c93e44d9aba2 to your computer and use it in GitHub Desktop.
Dynamic Type for some UI components
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// UINavigationBar title
[[UINavigationBar appearance] setTitleTextAttributes:@{NSFontAttributeName: [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline]}];
// UIBarButtonItem title
[[UIBarButtonItem appearance] setTitleTextAttributes:@{NSFontAttributeName: [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline]}
forState:UIControlStateNormal];
// UITabBarItem title
[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName: [UIFont preferredFontForTextStyle:UIFontTextStyleCaption1]}
forState:UIControlStateNormal];
// UISegmentedControl title
[[UISegmentedControl appearance] setTitleTextAttributes:@{NSFontAttributeName: [UIFont preferredFontForTextStyle:UIFontTextStyleBody]}
forState:UIControlStateNormal];
// UISearchBar text and placeholder
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setFont:[UIFont preferredFontForTextStyle:UIFontTextStyleBody]];
return YES;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment