苹果支持的字体
在开发过程中很多App为了美观经常需要使用一些自定义的字体,其实苹果本身也是支持很多字体的,下面就记录一下查看所有字体并设置的方法,其实挺简单的。
[UIFont fontWithName:@"" size:16];
这是UIFont的一个方法可以在设置字体大小的同时设置字体效果,@""里面可以填入相应的字体。
知道设置字体的方法了,就需要找出苹果本身支持的所有字体了,一个for循环就可以搞定了。
//[UIFont familyNames]里面存的就是苹果支持的所有字体
for (NSString *supportTheFont in [UIFont familyNames]) {
NSLog(@"字体%@",supportTheFont);
}
下面是所有的效果,可以在下面直接找需要的字体

自定义字体
不过发现这些效果对中文好像没什么效果,这就需要自定义字体了
1.将准备好的字体拉入项目中

2.打开Build Phases—Copy Bundle Resources,确保刚添加的字体文件在列表中,否则需要手动加到这里

3.编辑”项目名-Info.plist”文件
找到Fonts provided by application ,将加入的字体名连同扩展名填在这里

4.利用上面那个for循环打印出所有字体,并找到刚刚加入的字体

5.现在就可以使用了[UIFont fontWithName:@"chenweixun-yingxing" size:16];
网友评论