在故事板中创建后更改单元格的字体

时间:2014-08-25 14:48:11

标签: ios objective-c uitableview fonts

我有一个带有tableview的故事板。我桌上有4个牢房。他们有自己的标识符。问题是我不能以编程方式更改单元格的字体。我已经在项目中添加了字体,并在plist文件中添加了一个名为“由应用程序提供的字体”的数组中的新键。也许我需要重新加载数据,但我可以在哪里做?在viewWillAppear下它没用了

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [self.menuItems objectAtIndex:indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

[cell.textLabel setFont:[UIFont fontWithName:@"Xiomara" size:30]];

return cell;
} 

1 个答案:

答案 0 :(得分:0)

确保您使用的是正确的字体名称。

您可以使用此方法。

- (void)logFontNamesOfAllFonts
{
    NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];

    NSArray *fontNames;
    NSInteger indFamily, indFont;
    for (indFamily=0; indFamily<[familyNames count]; ++indFamily) {
        NSLog(@"Family name: %@", [familyNames objectAtIndex:indFamily]);
        fontNames = [[NSArray alloc] initWithArray:
                     [UIFont fontNamesForFamilyName:
                      [familyNames objectAtIndex:indFamily]]];
        for (indFont=0; indFont<[fontNames count]; ++indFont) {
            NSLog(@"    Font name: %@", [fontNames objectAtIndex:indFont]);
        }
    }
}

只需调用AppDelegate.m的applicationDidFinishLaunching:方法,然后查看字体的正确名称。
如果没有安装名称的字体,则表示您的字体未正确安装。