新增字体
2019-11-14 本文已影响0人
张_何
-
将字体文件拖入工程中,记得勾选对应的target
image.png
image.png -
在inof.plist文件中添加对应的字体的文件名
image.png -
使用
使用系统字体册打开字体文件,查看字体名字
image.png
image.png
- 或者打印出所有的字体,从中找出对应字体的名字
for (NSString *fontfamilyname in [UIFont familyNames])
{
NSLog(@"family:'%@'",fontfamilyname);
for(NSString *fontName in [UIFont fontNamesForFamilyName:fontfamilyname])
{
NSLog(@"\tfont:'%@'",fontName);
}
NSLog(@"-------------");
}
/*
family:'DIN Condensed'
font:'DINCondensed-Bold'
*/
*使用
UILabel *forte = [[UILabel alloc] init];
forte.frame = CGRectMake(20, UIScreen.mainScreen.bounds.size.height * 0.5 - 100, UIScreen.mainScreen.bounds.size.width - 40, 40);
forte.font = [UIFont fontWithName:@"Forte" size:30.f];
forte.textColor = UIColor.blackColor;
forte.text = @"Forte";
[self.view addSubview:forte];
UILabel *system = [[UILabel alloc] init];
system.frame = CGRectMake(20, UIScreen.mainScreen.bounds.size.height * 0.5, UIScreen.mainScreen.bounds.size.width - 40, 40);
system.font = [UIFont systemFontOfSize:30.0];
system.textColor = UIColor.blackColor;
system.text = @"system";
[self.view addSubview:system];
UILabel *DINCondensed = [[UILabel alloc] init];
DINCondensed.frame = CGRectMake(20, UIScreen.mainScreen.bounds.size.height * 0.5 + 100, UIScreen.mainScreen.bounds.size.width - 40, 40);
// 以下两种是效果是一样的
DINCondensed.font = [UIFont fontWithName:@"DIN Condensed" size:30.f];
// DINCondensed.font = [UIFont fontWithName:@"DINCondensed-Bold" size:30.f];
DINCondensed.textColor = UIColor.blackColor;
DINCondensed.text = @"DIN Condensed";
[self.view addSubview:DINCondensed];
NSLog(@"forte.font = %@", forte.font);
NSLog(@"system.font = %@", system.font);
NSLog(@"DINCondensed.font = %@", DINCondensed.font);
/*
forte.font = <UICTFont: 0x7fe4a6e100f0> font-family: "Forte"; font-weight: normal; font-style: italic; font-size: 30.00pt
system.font = <UICTFont: 0x7fe4a6e10ac0> font-family: ".SFUIDisplay"; font-weight: normal; font-style: normal; font-size: 30.00pt
DINCondensed.font = <UICTFont: 0x7fe4a6e111a0> font-family: "DIN Condensed"; font-weight: bold; font-style: normal; font-size: 30.00pt
*/
*显示
image.png
注意:
使用别人的字体要注意授权问题。最近我们使用的别人的字体被别人发现了,上诉到苹果告我们侵权,苹果告知如果不解决,我们的app将在app store 下架处理。