您可以使用以下方法检查您的设备(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;
}
第二步:在您的接口文件(.m)中,在viewDidLoad中填充您的数组。
-(void)viewDidLoad{
fontFamilies = [UIFont familyNames];
}
步骤三:最后,将此添加到你的cellForRowAtIndexPath方法中
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.textLabel.text = [fontFamilies objectAtIndex:indexPath.row];
cell.textLabel.font = [UIFont fontWithName:[fontFamilies objectAtIndex:indexPath.row] size:12];
return cell;
}
注意:确保您已连接委托和数据源。您在故事板(或xib)上的tableView单元格属性应为“Cell”,并确保:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return fontFamilies.count;
}
要了解有关表视图的更多信息,请查看苹果文档 这里
或者查看appCoda的表视图教程 这里