·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> app软件开发 >> IOS开发 >> iOS中使用自定义字体

iOS中使用自定义字体

作者:佚名      IOS开发编辑:admin      更新时间:2022-07-23

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代码  收藏代码
  1. - (void)viewDidLoad {  
  2.     NSString *imageName = @"grid.png";  
  3.     UIImageView * imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]];  
  4.     imageView.frame = CGRectMake(20, 20, 250, 250);  
  5.       
  6.     UILabel *test = [[UILabel alloc] init];  
  7.     test.frame = CGRectMake(95, 215, 200, 50);  
  8.     test.font=[UIFont fontWithName:@"HAKUYOGuiFanZi3500" size:30];  
  9.     test.text = @"原始图片";  
  10.     test.backgroundColor = [UIColor clearColor];  
  11.     [imageView addSubview:test];  
  12.     [test release];  
  13.       
  14.     [self.view addSubview:imageView];  
  15.     [imageView release];      
  16. }