1.添加对应的自体文件(.ttf或.otf等)到工程目录下,比如:SIMKAI.TTF
2.在-info.plist文件中添加一项Fonts provided by application,item0对应的value为SIMKAI.TTF,多个自体依次添加即可。
3.使用 [UIFont fontWithName: size:]来设置自体,fontWithName的参数不一定是SIMKAI,这个字体名字需要别的方法去查。
查字体名字方法如下:
for(NSString *familyName in [UIFont familyNames]) { NSLog(@"familyName = %@", familyName); for(NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) { NSLog(@"\tfontName = %@", fontName); } }
在上面第2步添加前和添加后的情况下分别执行如上代码,把控制台打印出的信息分别做记录。控制台打印信息示例:
2012-08-08 14:27:56.150[1821:c07] familyName = Thonburi 2012-08-08 14:27:56.153[1821:c07] fontName = Thonburi-Bold 2012-08-08 14:27:56.154[1821:c07] fontName = Thonburi 2012-08-08 14:27:56.154[1821:c07] familyName = Snell Roundhand 2012-08-08 14:27:56.154[1821:c07] fontName = SnellRoundhand-Bold 2012-08-08 14:27:56.155[1821:c07] fontName = SnellRoundhand-Black 2012-08-08 14:27:56.155[1821:c07] fontName = SnellRoundhand 2012-08-08 14:27:56.156[1821:c07] familyName = Academy Engraved LET 2012-08-08 14:27:56.156[1821:c07] fontName = AcademyEngravedLetPlain 2012-08-08 14:27:56.157[1821:c07] familyName = Marker Felt 2012-08-08 14:27:56.157[1821:c07] fontName = MarkerFelt-Wide 2012-08-08 14:27:56.158[1821:c07] fontName = MarkerFelt-Thin 2012-08-08 14:27:56.158[1821:c07] familyName = Geeza Pro 2012-08-08 14:27:56.159[1821:c07] fontName = GeezaPro-Bold 2012-08-08 14:27:56.159[1821:c07] fontName = GeezaPro 2012-08-08 14:27:56.182[1821:c07] familyName = Arial Rounded MT Bold 2012-08-08 14:27:56.183[1821:c07] fontName = ArialRoundedMTBold 2012-08-08 14:27:56.183[1821:c07] familyName = Trebuchet MS 2012-08-08 14:27:56.184[1821:c07] fontName = TrebuchetMS 2012-08-08 14:27:56.184[1821:c07] fontName = TrebuchetMS-Bold
用比较文件的方法找出2次从控制台打印出的信息的不同内容,这些不同的内容就是新添加进去的字体的名字。
从而可以看出,新添加进去的自体的名字就是 KaiTi_GB2312
设置自体的时候就应该如下操作:
[UIFont fontWithName:@"KaiTi_GB2312" size:20.0]