1.将xx.ttf字体库加入工程里面
2.在工程的xx-Info.plist文件中新添加一行Fonts provided by application,加上字体库的名称
3.引用字体库的名称,设置字体: [UIFont fontWithName:@"Hipchick" size:30];
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSLog(@"hipch___: %@",[UIFont fontNamesForFamilyName:@"Hipchick"]);
testLbl.font = [UIFont fontWithName:@"Hipchick" size:30];
testLbl.text = @"Frank Zappa";
}
4.如果不知道字体名称,可以遍历字体进行查询:
for(NSString *fontfamilyname in [UIFont familyNames])
{
NSLog(@"family:'%@'",fontfamilyname);
for(NSString *fontName in [UIFont fontNamesForFamilyName:fontfamilyname])
{
NSLog(@"\tfont:'%@'",fontName);
}
NSLog(@"-------------");
}
网友评论