ios 新增自定義字型
阿新 • • 發佈:2019-01-10
1.下載ttf字型。(到我的資源庫那可以下載字型)
2.新增字型到工程
3.在plist新增如下
4.檢查build phase裡有沒有新增進去
查詢所有字型程式碼,可放到viewdidload中
[cpp] view plaincopyprint?- NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];
- NSArray *fontNames;
- NSInteger indFamily, indFont;
-
for (indFamily=0; indFamily<[familyNames count]; ++indFamily)
- {
- NSLog(@"Family name: %@", [familyNames objectAtIndex:indFamily]);
- fontNames = [[NSArray alloc] initWithArray:
- [UIFont fontNamesForFamilyName:
- [familyNames objectAtIndex:indFamily]]];
-
for (indFont=0; indFont<[fontNames count]; ++indFont)
- {
- NSLog(@" Font name: %@", [fontNames objectAtIndex:indFont]);
- }
- }
這種方法打印出所有字型但很難找到你新增的字型,因為familyName不知道。找只有一個子集的familyname。
呼叫字型程式碼
[cpp] view plaincopyprint?- atkLabel.font= [UIFont fontWithName:@"DFGirlKelvin" size:14];