前言
一般我们用到的字体格式 —— .eot、.woff、.ttf、.svg
1.找到我们想要使用的字体,拖进项目里
比如笔者新添加一种新的字体Poppins-Medium.ttf
2.打开info.plist (open as source Code)
新添加一个键值对
<key>UIAppFonts</key>
<array>
<string>Poppins-Medium.tff</string>
</array>
3.target - Build Phase - Copy Bunble Resource 查看字体是否已经添加上
截屏2022-05-24 11.43.53.png4.我们可以打印出目前项目中所有的字体
NSArray *familyNames =[[NSArray alloc]initWithArray:[UIFont familyNames]];
NSArray *fontNames;
NSInteger indFamily, indFont;
PCLog(@"[familyNames count]===%zd",[familyNames count]);
for(indFamily=0;indFamily<[familyNames count];++indFamily)
{
PCLog(@"Family name: %@", [familyNames objectAtIndex:indFamily]);
fontNames =[[NSArray alloc]initWithArray:[UIFont fontNamesForFamilyName:[familyNames objectAtIndex:indFamily]]];
for(indFont=0; indFont<[fontNames count]; ++indFont)
{
PCLog(@"Font name: %@",[fontNames objectAtIndex:indFont]);
}
}
5.我们就可以使用我们新添加的字体
self.titleLabel.font = [UIFont fontWithName:@"Poppins-Medium" size:20];
网友评论