項目中想使用第三方的字體,在stackoverflow上查詢解決辦法,也折騰一會,添加成功,示例如下:
1.將xx.ttf字體庫加入工程裡面
2.在工程的xx-Info.plist文件中新添加一行Fonts provided by application,加上字體庫的名稱
3.引用字體庫的名稱,設置字體: [UIFontfontWithName:@"fontname" size:24];
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];
如果不知道字體名稱,可以遍歷字體進行查詢:
for(NSString *fontfamilyname in [UIFont familyNames]) { NSLog(@"family:'%@'",fontfamilyname); for(NSString *fontName in [UIFont fontNamesForFamilyName:fontfamilyname]) { NSLog(@"\tfont:'%@'",fontName); } NSLog(@"-------------"); }
示例Demo下載地址:http://download.csdn.net/detail/duxinfeng2010/7639683
參考http://stackoverflow.com/questions/15447558/can-not-include-ttf-font-into-project