方法步骤
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(@"---------------------------------------------");
}
}