Xác định và xuất (bằng cách bao gồm một tiêu đề trong các tập tin hoặc trong precompi dẫn tiêu đề) một loại của UIFont
như sau:
@implementation UIFont (Utils)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation"
+ (UIFont *)systemFontOfSize:(CGFloat)size
{
return [UIFont fontWithName:@"YOUR_TRUETYPE_FONT_NAME_HERE" size:size];
}
+ (UIFont *)lightSystemFontOfSize:(CGFloat)size
{
return [UIFont fontWithName:@"YOUR_TRUETYPE_FONT_NAME_HERE" size:size];
}
+ (UIFont *)boldSystemFontOfSize:(CGFloat)size
{
return [UIFont fontWithName:@"YOUR_TRUETYPE_FONT_NAME_HERE" size:size];
}
+ (UIFont *)preferredFontForTextStyle:(NSString *)style
{
if ([style isEqualToString:UIFontTextStyleBody])
return [UIFont systemFontOfSize:17];
if ([style isEqualToString:UIFontTextStyleHeadline])
return [UIFont boldSystemFontOfSize:17];
if ([style isEqualToString:UIFontTextStyleSubheadline])
return [UIFont systemFontOfSize:15];
if ([style isEqualToString:UIFontTextStyleFootnote])
return [UIFont systemFontOfSize:13];
if ([style isEqualToString:UIFontTextStyleCaption1])
return [UIFont systemFontOfSize:12];
if ([style isEqualToString:UIFontTextStyleCaption2])
return [UIFont systemFontOfSize:11];
return [UIFont systemFontOfSize:17];
}
#pragma clang diagnostic pop
@end
Biến thể nhẹ trở thành một bổ sung hữu ích bắt đầu với iOS 7. Hãy tận hưởng! ;)
Bạn đã thử tạo danh mục cho UIFont chưa? – NeverBe
Bạn có chắc chắn * bạn muốn thay đổi không? Đây là cách giao diện jarring được sinh ra. – Dave
@Dave: Có. Tôi chắc chắn tôi muốn thay đổi nó :) –