您可以使用此方法检查您的设备(iPhone 或 iPad)的可用字体
- (void)getAllFonts{
NSArray *fontFamilies =[UIFont familyNames];
for(int i =0; i <[fontFamilies count]; i++){
NSString *fontFamily =[fontFamilies objectAtIndex:i];
NSArray *fontNames =[UIFont fontNamesForFamilyName:[fontFamilies objectAtIndex:i]];
NSLog(@"%@: %@", fontFamily, fontNames);
}
}
复制/粘贴到一个类上并使用 [self getAllFonts];
该列表应显示在您的日志中
编辑:如果你想看看它是什么样子,我们使用表格视图怎么样
第 1 步:将其添加到您的标题中
@interface FontViewController (){
NSArray* fontFamilies;
}
第 2 步:在您的接口文件 (.m) 上,在 viewDidLoad 上填充您的数组。
-(void)viewDidLoad{
fontFamilies = [UIFont familyNames];
}
STEP3:最后,将这个添加到你的 cellForRowAtIndexPath 方法
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// The Magic :)
cell.textLabel.text = [fontFamilies objectAtIndex:indexPath.row];
cell.textLabel.font = [UIFont fontWithName:[fontFamilies objectAtIndex:indexPath.row] size:12];
return cell;
}
PS:确保已连接代理和数据源。情节提要(或 xib)上的 tableView Cell 属性应为“Cell”,并确保:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return fontFamilies.count;
}
有关表格视图的更多信息,请查看苹果文档here
或查看 appCoda 的 Table View 教程here