Skip to content

Instantly share code, notes, and snippets.

@zwaldowski
Created November 9, 2014 22:06
Show Gist options
  • Save zwaldowski/f29374e4069044811d9e to your computer and use it in GitHub Desktop.
Save zwaldowski/f29374e4069044811d9e to your computer and use it in GitHub Desktop.
Dynamic Type with Weight-Matching
@implementation UIFontDescriptor (DZWDynamicType)
+ (instancetype)dzw_preferredFontDescriptorWithTextStyle:(NSString *)style {
return [[self preferredFontDescriptorWithTextStyle:style] dzw_fontDescriptorWithMatchingFamily:@"Avenir Next"];
}
- (instancetype)dzw_fontDescriptorWithMatchingFamily:(NSString *)family {
NSMutableDictionary *attributes = [self.fontAttributes mutableCopy];
[attributes removeObjectForKey:UIFontDescriptorTextStyleAttribute];
UIFontDescriptor *newDesc = (__bridge_transfer UIFontDescriptor *)CTFontDescriptorCreateCopyWithFamily((__bridge CTFontDescriptorRef)self, (__bridge CFStringRef)family);
[attributes addEntriesFromDictionary:newDesc.fontAttributes];
return [self.class fontDescriptorWithFontAttributes:attributes];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment