可以通过一个方法获取所有的字体:
// 获取系统所有的字体
NSArray *TypefaceArray = [UIFont familyNames];
下面是我把字体全部复制了放入数组中,其他不多说,上实现内容:
// TypefaceController.m
//
// Created by user on 2016/11/3.
// Copyright © 2016年 user. All rights reserved.
//
#import "TypefaceController.h"
@interface TypefaceController ()<UITableViewDelegate,UITableViewDataSource>
@end
@implementation TypefaceController
{
NSArray *TypefaceArray;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1.0];
[self loadData];
[self creatTableView];
}
- (void)loadData
{
// 获取系统所有的字体
// NSArray *TypefaceArray = [UIFont familyNames];
TypefaceArray = @[@"Thonburi",@"Khmer Sangam MN",@"Kohinoor Telugu",@"Snell Roundhand",@"Academy Engraved LET",@"Marker Felt",@"Avenir",@"Geeza Pro",@"Arial Rounded MT Bold",@"Trebuchet MS",@"Arial",@"Menlo",@"Gurmukhi MN",@"Malayalam Sangam MN",@"Kannada Sangam MN",@"Bradley Hand",@"Bodoni 72 Oldstyle",@"Cochin",@"Sinhala Sangam MN",@"PingFang HK",@"Iowan Old Style",@"Kohinoor Bangla",@"Damascus",@"Farah",@"Papyrus",@"Verdana",@"Zapf Dingbats",@"Avenir Next Condensed",@"Courier",@"Hoefler Text",@"Euphemia UCAS",@"Helvetica",@"Lao Sangam MN",@"Hiragino Mincho ProN",@"Bodoni Ornaments",@"Apple Color Emoji",@"Mishafi",@"Optima",@"ujarati Sangam MN",@"Devanagari Sangam MN",@"PingFang SC",@"Savoye LET",@"Times New Roman",@"Kailasa",@"Telugu Sangam MN",@"Heiti SC",@"Apple SD Gothic Neo",@"Futura",@"Bodoni 72",@"Baskerville",@"Symbol",@"Heiti TC",@"Copperplate",@"Party LET",@"American Typewriter",@"Chalkboard SE",@"Avenir Next",@"Bangla Sangam MN",@"Noteworthy",@"Hiragino Sans",@"Zapfino",@"Tamil Sangam MN",@"Chalkduster",@"Arial Hebrew",@"Georgia",@"Helvetica Neue",@" Gill Sans",@"Kohinoor Devanagari",@"Palatino",@"Courier New",@"Oriya Sangam MN",@"Didot",@"PingFang TC",@"Bodoni 72 Smallcaps"];
}
- (void)creatTableView
{
UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
tableView.delegate = self;
tableView.dataSource = self;
[self.view addSubview:tableView];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return TypefaceArray.count;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellID = @"cellID";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
}
cell.textLabel.text = [NSString stringWithFormat:@"字体样式12 %@", TypefaceArray[indexPath.row]];
cell.textLabel.font = [UIFont fontWithName:TypefaceArray[indexPath.row] size:12];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
NSLog(@"选中字体: %@",cell.textLabel.text);
}
运行的效果很明显: