iOS中使用自定义字体

王朝学院·作者佚名  2016-08-27
窄屏简体版  字體: 小  |  中  |  大  |  超大  

1、确定你的项目工程的Resources下有你要用的字体文件(.ttf或者.odf)。

2、然后在你的工程的Info.plist文件中新建一行,添加key为:UIAppFonts,类型为Array或Dictionary都行,在UIAppFonts下再建立一个键值对,key为:Item 0,添加Value为XXX.ttf(字体的名字,string型),可以添加多个,使用的时候写对应字体名字就行。

3、在你的项目里要用字体的时候 xx.font = [UIFont fontWithName:@"XXX" size:20.0],这样就可以了。

Ios代码

- (void)viewDidLoad { NSString *imageName = @"grid.png"; UIImageView * imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]]; imageView.frame = CGRectMake(20, 20, 250, 250); UILabel *test = [[UILabel alloc] init]; test.frame = CGRectMake(95, 215, 200, 50); test.font=[UIFont fontWithName:@"HAKUYOGuiFanZi3500" size:30]; test.text = @"原始图片"; test.backgroundColor = [UIColor clearColor]; [imageView addSubview:test]; [test release]; [self.view addSubview:imageView]; [imageView release]; }

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航