Created
January 14, 2014 14:51
-
-
Save holysin/8419473 to your computer and use it in GitHub Desktop.
Get the variation of the UIFont
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UIFont * GetVariationOfFontWithTrait(UIFont *baseFont, CTFontSymbolicTraits trait) { | |
CGFloat fontSize = [baseFont pointSize]; | |
CFStringRef baseFontName = (__bridge CFStringRef)[baseFont fontName]; | |
CTFontRef baseCTFont = CTFontCreateWithName(baseFontName, fontSize, NULL); | |
CTFontRef ctFont = CTFontCreateCopyWithSymbolicTraits(baseCTFont, 0, NULL, trait, trait); | |
NSString *variantFontName = CFBridgingRelease(CTFontCopyName(ctFont, kCTFontPostScriptNameKey)); | |
UIFont *variantFont = [UIFont fontWithName:variantFontName size:fontSize]; | |
CFRelease(ctFont); | |
CFRelease(baseCTFont); | |
return variationFont; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment