- 將TTF字體文件導入工程
2.設置plist文件如下
Paste_Image.png
或者在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.png
demo 下載地址:https://github.com/SuperManHAKA/TTF-Demo