Last active
March 8, 2022 11:12
-
-
Save zhaoyk/9823633 to your computer and use it in GitHub Desktop.
UIFont 与 CTFontRef 互相转换
This file contains hidden or 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 *)uifontFromCTFontRef:(CTFontRef)ctFont { | |
CGFloat pointSize = CTFontGetSize(ctFont); | |
NSString *fontPostScriptName = (NSString *)CFBridgingRelease(CTFontCopyPostScriptName(ctFont)); | |
UIFont *fontFromCTFont = [UIFont fontWithName:fontPostScriptName size:pointSize]; | |
return fontFromCTFont; | |
} | |
+ (CTFontRef)ctFontRefFromUIFont:(UIFont *)font { | |
CTFontRef ctfont = CTFontCreateWithName((__bridge CFStringRef)font.fontName, font.pointSize, NULL); | |
return CFAutorelease(ctfont); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
尝试用机器转 swift 却发现还不能直接用在 Swift 当中。
