From 4efcd0222b32d924486d0a171ed9d69492ea8e98 Mon Sep 17 00:00:00 2001 From: Chris Song Date: Fri, 28 Jun 2013 16:18:24 +0800 Subject: [PATCH] add UIFont::italicSystemFontOfSize --- UIKit/Classes/UIFont.h | 1 + UIKit/Classes/UIFont.m | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/UIKit/Classes/UIFont.h b/UIKit/Classes/UIFont.h index 80d6ee9a..90991035 100644 --- a/UIKit/Classes/UIFont.h +++ b/UIKit/Classes/UIFont.h @@ -40,6 +40,7 @@ + (UIFont *)systemFontOfSize:(CGFloat)fontSize; + (UIFont *)boldSystemFontOfSize:(CGFloat)fontSize; ++ (UIFont *)italicSystemFontOfSize:(CGFloat)fontSize; - (UIFont *)fontWithSize:(CGFloat)fontSize; diff --git a/UIKit/Classes/UIFont.m b/UIKit/Classes/UIFont.m index dcbab16e..62ad0718 100644 --- a/UIKit/Classes/UIFont.m +++ b/UIKit/Classes/UIFont.m @@ -32,6 +32,7 @@ static NSString *UIFontSystemFontName = nil; static NSString *UIFontBoldSystemFontName = nil; +static NSString *UIFontItalicSystemFontName = nil; @implementation UIFont @@ -47,6 +48,12 @@ + (void)setBoldSystemFontName:(NSString *)aName UIFontBoldSystemFontName = [aName copy]; } ++ (void)setItalicSystemFontName:(NSString *)aName +{ + [UIFontItalicSystemFontName release]; + UIFontItalicSystemFontName = [aName copy]; +} + + (UIFont *)_fontWithCTFont:(CTFontRef)aFont { UIFont *theFont = [[UIFont alloc] init]; @@ -137,6 +144,18 @@ + (UIFont *)boldSystemFontOfSize:(CGFloat)fontSize return [self fontWithNSFont:systemFont]; } ++ (UIFont *)italicSystemFontOfSize:(CGFloat)fontSize +{ + NSFont *systemFont; + if (UIFontBoldSystemFontName) { + systemFont = [NSFont fontWithName:UIFontItalicSystemFontName size:fontSize]; + } else { + NSFont * font = [NSFont boldSystemFontOfSize:fontSize]; + systemFont = [[NSFontManager sharedFontManager] convertFont:font toHaveTrait:NSUnboldFontMask | NSItalicFontMask]; + } + return [self fontWithNSFont:systemFont]; +} + - (void)dealloc { if (_font) CFRelease(_font);