iOS 获取自定义字体名称并使用

  1. 将字体文件xx.tff拖入工程。
  2. 在info.plist任意键值对上按右键\Add Row,添加一个新键"Fonts provided by application",如图
    在这里插入图片描述
  3. 执行下面代码获取xx.tff对应的字体族名称,字体名称。
NSArray* familys = [UIFont familyNames];
for (int i = 0; i < [familys count]; i++) {
	NSString* family = [familys objectAtIndex:i];
	NSLog(@”字体族名称:%@=====, family);
	NSArray* fonts = [UIFont fontNamesForFamilyName:family];
	for (int j = 0; j < [fonts count]; j++) {
		NSLog(@”字体名称:%@, [fonts objectAtIndex:j]);
	}
}
  1. 以后在代码里就可以用
xx.font = [UIFont fontWithName:@"字体名称" size:字号大小]

你可能感兴趣的:(iOS)