您的位置:首页 > 移动开发 > IOS开发

iOS中使用自定义字体

2014-09-15 08:48 309 查看
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];

}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: