1. UIFont用法
UIFont
用于获取和设置字体信息。
获取指定大小的字体
// 返回指定字体大小的标准样式
+ (UIFont *)systemFontOfSize:(CGFloat)fontSize;
//返回指定字体大小的粗体样式
+ (UIFont *)boldSystemFontOfSize:(CGFloat)fontSize;
// 返回指定字体大小的斜体样式
+ (UIFont *)italicSystemFontOfSize:(CGFloat)fontSize;
// UIFontWeight指定字体大小的粗细程度
+ (UIFont *)systemFontOfSize:(CGFloat)fontSize weight:(UIFontWeight)weight;
UIFontWeight
可以取下面的值
变量名 | 说明 |
---|---|
UIFontWeightUltraLight | 超细字体 |
UIFontWeightThin | 纤细字体 |
UIFontWeightLight | 亮字体 |
UIFontWeightRegular | 常规字体 |
UIFontWeightMedium | 介于Regular和Semibold之间 |
UIFontWeightSemibold | 半粗字体 |
UIFontWeightBold | 加粗字体 |
UIFontWeightHeavy | 介于Bold和Black之间 |
UIFontWeightBlack | 最粗字体 |
2. 主要属性
// 字体的family名称
@property(nonatomic,readonly,strong) NSString *familyName;
// 字体名称
@property(nonatomic,readonly,strong) NSString *fontName;
// 字体大小
@property(nonatomic,readonly) CGFloat pointSize;
// 大文字的高度
@property(nonatomic,readonly) CGFloat capHeight;
// 小文字的高度
@property(nonatomic,readonly) CGFloat xHeight;
// 行的高度
@property(nonatomic,readonly) CGFloat lineHeight;
3. 字体family和名称
// 返回指定字体名称的样式
+ (UIFont *)fontWithName:(NSString *)fontName size:(CGFloat)fontSize;
// 获取所有字体的family名称
@property(class, nonatomic, readonly) NSArray<NSString *> *familyNames;
// 获取指定family下所有字体样式
+ (NSArray<NSString *> *)fontNamesForFamilyName:(NSString *)familyName;
4. 获取用户偏好字体大小
获取系统字体大小
// Label使用的标准字体大小
@property(class, nonatomic, readonly) CGFloat labelFontSize;
// 按钮使用的标准字体大小
@property(class, nonatomic, readonly) CGFloat buttonFontSize;
// 比系统标准字体小的字体大小
@property(class, nonatomic, readonly) CGFloat smallSystemFontSize;
// 标准字体大小
@property(class, nonatomic, readonly) CGFloat systemFontSize;
5. 动态字体
动态字体可指定特殊的字体样式
+ (UIFont *)preferredFontForTextStyle:(UITextStyle)style;
UITextStyle
可以取下面的值
变量名 | 说明 |
---|---|
UIFontTextStyleTitle1 | 标题1字体样式 |
UIFontTextStyleTitle2 | 标题2字体样式 |
UIFontTextStyleTitle3 | 标题3字体样式 |
UIFontTextStyleHeadline | 大标题字体样式 |
UIFontTextStyleSubheadline | 小标题字体样式 |
UIFontTextStyleBody | 内容字体样式 |
UIFontTextStyleCallout | 插图字体样式 |
UIFontTextStyleFootnote | 脚注字体样式 |
UIFontTextStyleCaption1 | 说明1字体样式 |
UIFontTextStyleCaption2 | 说明2字体样式 |
相关文章