使用自定義字體 TTF文件 - iOS

  1. 將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

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容