SwiftUI一起学之五 -- 使用自定义字体
2021-05-12 本文已影响0人
sunny_ke_ke
一 目标
在SwiftUI中使用自定义的字体
二 效果

三 操作步骤
3.1 在项目上字体新建文件夹如Font,并添加字体文件到文件夹

3.2 在Info.plist文件中配置字体
(1)点击进入 info.plist,空白处点击右键选择 “ Add Row ” 或者点击文件中的 “ + ” 号,新建一个 Row ,选择 “ Fonts provided by application ” ;
(2)将鼠标移动至 “ Fonts provided by application ”,会出现一个 “ + ” 号,点击 “ + ” 即可新建一个子 “ Item ”,在 “ value ”栏输入字体的全称;如下图所示:

3.3 在代码中设置字体
import SwiftUI
struct FontUIView: View {
var body: some View {
VStack{
Text("默认字体").font(.system(size:50))
Text("自定义的字体")
.font(.custom("qiandoKws", size: 50))
}
}
}
struct FontUIView_Previews: PreviewProvider {
static var previews: some View {
FontUIView()
}
}
参考: