iOS UIFont简介

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字体样式

相关文章

iOS UIFont简介
iOS UIFont自定义字体

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值