項目中想使用第三方的字體,在stackoverflow上查詢解決辦法,也折騰一會,添加成功,示例以下:app
1.將xx.ttf字體庫加入工程裏面ide
2.在工程的xx-Info.plist文件中新添加一行Fonts provided by application,加上字體庫的名稱字體
3.引用字體庫的名稱,設置字體: [UIFontfontWithName:@"fontname" size:24];spa
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];
若是不知道字體是名稱,能夠遍歷字體進行查詢:3d
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 orm
參考http://stackoverflow.com/questions/15447558/can-not-include-ttf-font-into-projectblog