美文网首页
设置字体 systemFontOfSize: weight:

设置字体 systemFontOfSize: weight:

作者: 伯牙呀 | 来源:发表于2018-06-04 16:51 被阅读76次

使用下述方法设置UIFont:

UIFont *font = [UIFont systemFontOfSize:18 weight:UIFontWeightLight];

这个方法是 iOS8.2 之后出来的,但是 iOS8.0 上也能运行这个方法,只不过在 8.2 时才将这个方法变为共有API。

参数 size 是字体大小,参数 weight 是UIFontWeight(粗细)。

UIFontWeight的值:从上到下依次加粗

// Suggested values for use with UIFontWeightTrait, and UIFont's systemFontOfSize:weight:
// Beware that most fonts will _not_ have variants available in all these weights!
UIKIT_EXTERN const UIFontWeight UIFontWeightUltraLight  // 超细字体
UIKIT_EXTERN const UIFontWeight UIFontWeightThin        // 纤细字体
UIKIT_EXTERN const UIFontWeight UIFontWeightLight       // 轻量字体
UIKIT_EXTERN const UIFontWeight UIFontWeightRegular     // 常规字体
UIKIT_EXTERN const UIFontWeight UIFontWeightMedium      // 中等字体
UIKIT_EXTERN const UIFontWeight UIFontWeightSemibold    // 半粗字体
UIKIT_EXTERN const UIFontWeight UIFontWeightBold        // 加粗字体
UIKIT_EXTERN const UIFontWeight UIFontWeightHeavy       // 重粗字体
UIKIT_EXTERN const UIFontWeight UIFontWeightBlack       // 最粗字体

在size=18时,设置不同weight的效果对比:


相关文章

网友评论

      本文标题:设置字体 systemFontOfSize: weight:

      本文链接:https://www.haomeiwen.com/subject/slsysftx.html