Phone系统的字体数量有限,并且多数对中文没有效果,下面介绍两种解决办法
方法1:
添加对应的字体(.ttf或.odf)到工程的resurce,使用cocos2d中的FontLabel库,FontLabel继承于UILabel,象UILabel一样使用就好了
fontName直接使用添加的资源名字即可.
这方法我没有研究过,下面这个方法是可以的,并且有demo。
方法2:
1,添加对应的字体(.ttf或.odf)到工程的resurce,例如simkai.ttf
2,在info.plist中添加一项 Fonts provided by application (item0对应的value为simkai.ttf,添加多个字体依次添加就可以了)
3,使用时 aLabel.font=[UIFont fontWithName:@"XXX" size:30]; 注意XXX不一定是DFPShaoNvW5-GB1111(DFPShaoNvW5-GB1111文件名不代表字体名称),这里是DFPShaoNvW5-GB,你可以通过下面的方法遍历所有字体
- - (void)showAllFonts
- {
- //显示系统中所有的字体
- NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];
- for (int indFamily=0; indFamily<[familyNames count]; ++indFamily) {
- NSMutableString *string = [NSMutableString stringWithFormat:@"Family name:%@ (Font name:", [familyNames objectAtIndex:indFamily]];
- NSArray *fontNames = [[NSArray alloc] initWithArray: [UIFont fontNamesForFamilyName:[familyNames objectAtIndex:indFamily]]];
- for (int indFont=0; indFont<[fontNames count]; ++indFont) {
- [string appendFormat:@"%@, ", [fontNames objectAtIndex:indFont]];
- }
- [string appendFormat:@")"];
- CFShow(string);
- [fontNames release];
- }
- [familyNames release];
- }
使用方法:
- UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(30, 30, 200, 60)];
- label.font = [UIFont fontWithName:@"DFPShaoNvW5-GB" size:20];
- label.backgroundColor = [UIColor clearColor];
- label.text = @"中文abc123";
- [self.view addSubview:label];
- [label release];
效果: