- 将TTF字体文件导入工程
2.设置plist文件如下
或者在plist文件 source code 添加
<array>
<string>StencilStd.ttf</string>
<string>DS-DIGI.TTF</string>
<string>DS-DIGIB.TTF</string>
</array>
Paste_Image.png
Paste_Image.png
3.遍历字体
//遍历所有字体并输出
NSArray * fontArrays = [[NSArray alloc] initWithArray:[UIFont familyNames]];
for (NSString * temp in fontArrays) {
NSLog(@"Font name = %@", temp);
}
4.设置字体
UILabel * testLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 100, self.view.bounds.size.width - 20, 200)];
testLabel.numberOfLines = 0;
//选择自己添加字体 注意!!名称有可能改变 我添加的字体名称是DS-DIGI 但是输出是DS-Digital
testLabel.font = [UIFont fontWithName:@"DS-Digital" size:26];
testLabel.text = @"ABCDEFGHIJKLMNOPQRSTWVUXYZ1234567890";
[self.view addSubview:testLabel];
//用来做对比
UILabel * testLabelOne = [[UILabel alloc]initWithFrame:CGRectMake(10, 400, self.view.bounds.size.width - 20, 80)];
testLabelOne.numberOfLines = 0;
testLabelOne.text = @"ABCDEFGHIJKLMNOPQRSTWVUXYZ1234567890";
[self.view addSubview:testLabelOne];
5 storyBoard 设置
添加label 控件 设置如图
Paste_Image.png展示图
Paste_Image.pngdemo 下载地址:https://github.com/SuperManHAKA/TTF-Demo
网友评论