Skip to content

Instantly share code, notes, and snippets.

@myell0w
Last active January 2, 2016 14:09
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myell0w/8315322 to your computer and use it in GitHub Desktop.
Save myell0w/8315322 to your computer and use it in GitHub Desktop.
Respect the accessibility setting "Bold Text" on iOS7, when implementing Dynamic Type with a custom font.
BOOL MTDIsBoldTextEnabled(void) {
static BOOL boldTextEnabled = NO;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// Hack that checks if the "bold text" flag in the accessibility settings is enabled
UIFont *font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
boldTextEnabled = [font.fontName rangeOfString:@"MediumP4"].location != NSNotFound;
});
return boldTextEnabled;
}
@myell0w
Copy link
Author

myell0w commented Jan 8, 2014

Is there any less hacky way to detect this setting? I couldn't figure it out, use at own risk.

@steipete
Copy link

steipete commented Jan 8, 2014

dispatch_once might not be a good idea - since that can be changed at runtime as well...

@mmackh
Copy link

mmackh commented Jan 8, 2014

Wouldn't the kernel be patched (https://twitter.com/GlennF/status/400058776738205696) and all apps killed? I think dispatch_once is correct in this instance.

@myell0w
Copy link
Author

myell0w commented Jan 8, 2014

still running iOS 7.0.4, up until then it restarts iOS and the app gets killed. Didn't test it on iOS 7.1 Beta though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment