方法步骤
steps 1:下载字体资源(请滑至本文底部进行字体资源下载)
steps 2:将下载下来的字体资源文件按需拖入到项目工程中
steps 3:修改
Info.plist,添加Fonts provided by application属性(Array类型),点击+将需要添加的字体加入到该字段中。steps 4:【故事板使用】打开布局文件
Main.storyboard,拖一个UILabel控件到界面里,修改UILabel的字体属性Font->Custom,Font Family->STXingkai(华文行楷)steps 4:【源代码使用】打开源码文件ViewController.m,创建文本标签,设置字体,配置属性,添加视图
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UILabel *displayLabel = [[UILabel alloc] init];
displayLabel.bounds = CGRectMake(0, 0, 220, 30);
displayLabel.center = self.view.center;
displayLabel.numberOfLines = 0;
displayLabel.textAlignment = NSTextAlignmentCenter;
displayLabel.text = @"三方字体使用";
displayLabel.font = [UIFont fontWithName:@"STXingkai" size:25];
[displayLabel sizeToFit];
[self.view addSubview:displayLabel];
}
获取字体名(font name)
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 遍历字体
for (NSString *fontFamilyName in [UIFont familyNames]) {
NSLog(@"family:'%@'",fontFamilyName);
for(NSString *fontName in [UIFont fontNamesForFamilyName:fontFamilyName]) {
NSLog(@"\t font:'%@'",fontName);
}
NSLog(@"---------------------------------------------");
}
}
本文详细介绍了如何在iOS应用中使用第三方字体,包括下载字体资源、添加到项目、修改Info.plist文件以及在故事板和源代码中应用字体的完整步骤。
1768

被折叠的 条评论
为什么被折叠?



