項目中想使用第三方的字體,在stackoverflow上查詢解決辦法,也折騰一會,添加成功,示例如下:
1.將xx.ttf字體庫加入工程裏面
2.在工程的xx-Info.plist文件中新添加一行Fonts provided by application,加上字體庫的名稱
3.引用字體庫的名稱,設置字體: [UIFontfontWithName:@"fontname" size:24];
1 2 3 4 5 | UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 100, 300, 50)]; label.text = @ "這是一個TEST。123456" ; UIFont *font = [UIFont fontWithName:@ "文鼎CS中等線" size:24]; label.font = font; [self.view addSubview:label]; |
如果不知道字體是名稱,可以遍歷字體進行查詢:
1 2 3 4 5 6 7 8 9 | for (NSString *fontfamilyname in [UIFont familyNames]) { NSLog(@ "family:'%@'" ,fontfamilyname); for (NSString *fontName in [UIFont fontNamesForFamilyName:fontfamilyname]) { NSLog(@ "\tfont:'%@'" ,fontName); } NSLog(@ "-------------" ); } |
示例Demo下載地址:http://down.51cto.com/3911492/up
參考http://stackoverflow.com/questions/15447558/can-not-include-ttf-font-into-project
本文出自 “新風作浪” 博客,請務必保留此出處http://duxinfeng.blog.51cto.com/3911492/1438678