Skip to content

Commit

Permalink
[Typography] font initializer based on style and Dynamic Type (#2666)
Browse files Browse the repository at this point in the history
  • Loading branch information
ianegordon committed Dec 11, 2017
1 parent 1663ee2 commit 93e21f1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions components/Typography/src/UIFont+MaterialTypography.h
Expand Up @@ -35,4 +35,14 @@
*/
+ (nonnull UIFont *)mdc_standardFontForMaterialTextStyle:(MDCFontTextStyle)style;

/**
Returns an new instance of the font sized according to the text-style and whether the content
size category (Dynamic Type) should be taken into account.
@param style The Material font text style that will determine the fontSize of the new font
@param scaled Should the new font be scaled according to the content size category (Dynamic Type)
*/
- (nonnull UIFont *)mdc_fontSizedForMaterialTextStyle:(MDCFontTextStyle)style
scaledForDynamicType:(BOOL)scaled;

@end
12 changes: 12 additions & 0 deletions components/Typography/src/UIFont+MaterialTypography.m
Expand Up @@ -52,4 +52,16 @@ + (nonnull UIFont *)mdc_standardFontForMaterialTextStyle:(MDCFontTextStyle)style
return font;
}

- (nonnull UIFont *)mdc_fontSizedForMaterialTextStyle:(MDCFontTextStyle)style
scaledForDynamicType:(BOOL)scaled {
UIFontDescriptor *fontDescriptor;
if (scaled) {
fontDescriptor = [UIFontDescriptor mdc_preferredFontDescriptorForMaterialTextStyle:style];
} else {
fontDescriptor = [UIFontDescriptor mdc_standardFontDescriptorForMaterialTextStyle:style];
}

return [self fontWithSize:fontDescriptor.pointSize];
}

@end

0 comments on commit 93e21f1

Please sign in to comment.