您可以使用此方法检查您的设备(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);
}
}
Run Code Online (Sandbox Code Playgroud)
将其复制/粘贴到类上并使用 [self getAllFonts];
该列表应显示在您的日志中
第 1 步:将其添加到您的标题中
@interface FontViewController (){
NSArray* fontFamilies;
}
Run Code Online (Sandbox Code Playgroud)
第 2 步:在界面文件 (.m) 上,在 viewDidLoad 上填充数组。
-(void)viewDidLoad{
fontFamilies = [UIFont familyNames];
}
Run Code Online (Sandbox Code Playgroud)
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;
}
Run Code Online (Sandbox Code Playgroud)
PS:确保您已连接委托和数据源。故事板(或 xib)上的 tableView Cell 属性应该是“Cell”,并确保:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return fontFamilies.count;
}
Run Code Online (Sandbox Code Playgroud)
或者在此处查看 appCoda 的表视图教程
| 归档时间: |
|
| 查看次数: |
6663 次 |
| 最近记录: |