Skip to content

Instantly share code, notes, and snippets.

@bobspryn
Created February 19, 2014 02:36
Show Gist options
  • Select an option

  • Save bobspryn/9085066 to your computer and use it in GitHub Desktop.

Select an option

Save bobspryn/9085066 to your computer and use it in GitHub Desktop.
prefferedFont.m
+(UIFontDescriptor *)preferredAvenirNextFontDescriptorWithTextStyle:(NSString *)style {
static dispatch_once_t onceToken;
static NSDictionary *fontSizeTable;
dispatch_once(&onceToken, ^{
fontSizeTable = @{
UIFontTextStyleHeadline: @{UIContentSizeCategoryExtraExtraExtraLarge: @(23),
UIContentSizeCategoryExtraExtraLarge: @(21),
UIContentSizeCategoryExtraLarge: @(18),
UIContentSizeCategoryLarge: @(16),
UIContentSizeCategoryMedium: @(15),
UIContentSizeCategorySmall: @(14),
UIContentSizeCategoryExtraSmall: @(13),},
UIFontTextStyleSubheadline: @{UIContentSizeCategoryExtraExtraExtraLarge: @(22),
UIContentSizeCategoryExtraExtraLarge: @(20),
UIContentSizeCategoryExtraLarge: @(17),
UIContentSizeCategoryLarge: @(16),
UIContentSizeCategoryMedium: @(14),
UIContentSizeCategorySmall: @(13),
UIContentSizeCategoryExtraSmall: @(12),},
UIFontTextStyleBody: @{UIContentSizeCategoryExtraExtraExtraLarge: @(21),
UIContentSizeCategoryExtraExtraLarge: @(19),
UIContentSizeCategoryExtraLarge: @(16),
UIContentSizeCategoryLarge: @(15),
UIContentSizeCategoryMedium: @(14),
UIContentSizeCategorySmall: @(12),
UIContentSizeCategoryExtraSmall: @(12),},
UIFontTextStyleCaption1: @{UIContentSizeCategoryExtraExtraExtraLarge: @(20),
UIContentSizeCategoryExtraExtraLarge: @(18),
UIContentSizeCategoryExtraLarge: @(15),
UIContentSizeCategoryLarge: @(14),
UIContentSizeCategoryMedium: @(13),
UIContentSizeCategorySmall: @(12),
UIContentSizeCategoryExtraSmall: @(11),},
UIFontTextStyleCaption2: @{UIContentSizeCategoryExtraExtraExtraLarge: @(19),
UIContentSizeCategoryExtraExtraLarge: @(17),
UIContentSizeCategoryExtraLarge: @(14),
UIContentSizeCategoryLarge: @(13),
UIContentSizeCategoryMedium: @(12),
UIContentSizeCategorySmall: @(12),
UIContentSizeCategoryExtraSmall: @(11),},
ANUIFontTextStyleCaption3: @{UIContentSizeCategoryExtraExtraExtraLarge: @(18),
UIContentSizeCategoryExtraExtraLarge: @(16),
UIContentSizeCategoryExtraLarge: @(13),
UIContentSizeCategoryLarge: @(12),
UIContentSizeCategoryMedium: @(12),
UIContentSizeCategorySmall: @(11),
UIContentSizeCategoryExtraSmall: @(10),},
UIFontTextStyleFootnote: @{UIContentSizeCategoryExtraExtraExtraLarge: @(17),
UIContentSizeCategoryExtraExtraLarge: @(15),
UIContentSizeCategoryExtraLarge: @(12),
UIContentSizeCategoryLarge: @(12),
UIContentSizeCategoryMedium: @(11),
UIContentSizeCategorySmall: @(10),
UIContentSizeCategoryExtraSmall: @(10),},
};
});
NSString *contentSize = [UIApplication sharedApplication].preferredContentSizeCategory;
return [UIFontDescriptor fontDescriptorWithName:[self preferredFontName] size:((NSNumber *)fontSizeTable[style][contentSize]).floatValue];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment