iOS 7中的slim系统字体的名称是什么?有没有像UIFont systemFontOfSize:
一样使用它的方法?
答案 0 :(得分:27)
答案 1 :(得分:22)
从iOS 8.2开始,您现在可以使用UIFont.systemFontOfSize(_:CGFloat,weight:CGFloat)
:
UIFont.systemFontOfSize(19, weight: UIFontWeightLight)
iOS SDK为权重提供了常量:
UIFontWeightUltraLight
UIFontWeightThin
UIFontWeightLight
UIFontWeightRegular
UIFontWeightMedium
UIFontWeightSemibold
UIFontWeightBold
UIFontWeightHeavy
当你想使用系统字体时,使用系统字体比创建基于字体名称的字体更好,因为iOS可以在iOS上更改他们的系统字体(就像他们在iOS 7中使用Helvetica Neue一样,现在,旧金山iOS 9)。
答案 2 :(得分:1)
只需为UIFont进行扩展,如下所示
extension UIFont {
static func lightSystemFontOfSize(size: CGFloat) -> UIFont {
let familyName = UIFont.systemFontOfSize(15).familyName.stringByReplacingOccurrencesOfString(" ", withString: "")
return UIFont(name: "\(familyName)-Light", size: size)!
}
}
答案 3 :(得分:0)
刚刚为它创建了一个类别:
#import <UIKit/UIKit.h>
@interface UIFont (System)
+ (UIFont *)lightSystemFontOfSize:(CGFloat)fontSize;
+ (UIFont *)ultraLightSystemFontOfSize:(CGFloat)fontSize;
@end
#import "UIFont+System.h"
@implementation UIFont (System)
+ (UIFont *)lightSystemFontOfSize:(CGFloat)fontSize {
return [UIFont fontWithName:@"HelveticaNeue-Light" size:fontSize];
}
+ (UIFont *)ultraLightSystemFontOfSize:(CGFloat)fontSize {
return [UIFont fontWithName:@"HelveticaNeue-UltraLight" size:fontSize];
}
@end