iOS字体相关

时间:2022-02-19 20:44:40

1.使用自定义字体

(1)将字体文件导入项目

iOS字体相关

(2)在info.plist文件中添加 Fonts provided by application

iOS字体相关

(3)获取字体在项目中的名称

for fontFamilyName in UIFont.familyNames {
print("-------------family:\(fontFamilyName)")
for fontName in UIFont.fontNames(forFamilyName: fontFamilyName) {
print("\tfont:\(fontName)");
}
}

(4)双击打开导入的字体,获取名称

iOS字体相关

(5)获取自定义字体名称

iOS字体相关

(6)使用字体

UIFont.init(name: "SourceHanSansCN-Regular", size: fontSize)!