OGeek|极客世界-中国程序员成长平台

标题: ios - UITableViewCell 显示混合字体 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 22:15
标题: ios - UITableViewCell 显示混合字体

由于某种原因,我的 UITableViewCell 显示混合字体。这是一个演示我的意思的屏幕截图:

Mixed fonts on a single UITableViewCell

注意每一行的最后一个数字是错误的字体。根据我的测试,哪个字符被弄乱有点随机,所以不要因为它是这个屏幕截图中的最后一个字符而让你失望。

这是我设置字体的代码:

- (void)tableViewUITableView *)tableView willDisplayCellUITableViewCell *)cell forRowAtIndexPathNSIndexPath *)indexPath {
    UIImageView *iv;

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        [[cell textLabel] setFont: [UIFont fontWithName"BangBang" size: 36.0]];
        [[cell detailTextLabel] setFont: [UIFont fontWithName"BangBang" size: 32.0]];
        iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed: @"woodTableRow~ipad.png"]];
    } else {        
        [[cell textLabel] setFont: [UIFont fontWithName"BangBang" size: 22.0]];
        [[cell detailTextLabel] setFont: [UIFont fontWithName"BangBang" size: 22.0]];
        iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed: @"woodTableRow.png"]];
    }

    [cell setBackgroundView: iv];
    [iv release];

    cell.textLabel.textColor = [UIColor blackColor];
    [[cell textLabel] setShadowColor: [UIColor whiteColor]];
    [[cell textLabel] setShadowOffset: CGSizeMake(0, 1)];
    [[cell textLabel] setBackgroundColor: [UIColor clearColor]];

    cell.detailTextLabel.textColor = [UIColor blackColor];
    [[cell detailTextLabel] setShadowColor: [UIColor whiteColor]];
    [[cell detailTextLabel] setShadowOffset: CGSizeMake(0, 1)];
    [[cell detailTextLabel] setBackgroundColor: [UIColor clearColor]];

    switch (indexPath.row) {
        case ScoreRow:
            [[cell textLabel] setText: @"Score"];
            [[cell detailTextLabel] setText: @"1,234"];
            break;
        case TimeRow:
            [[cell textLabel] setText: @"Time"];
            [[cell detailTextLabel] setText: @"0:39"];
            break;
        default:
            [[cell textLabel] setText: @""];
            [[cell detailTextLabel] setText: @""];
            break;
    }
}

这对我来说毫无意义。有人可以帮忙吗?

更新:

我应该注意,我已经查看了这两个 StackOverFlow 问题,但都没有帮助:

UITableViewCell Font Not Changing

What is -[UITableViewDelegate willDisplayCell:forRowAtIndexPath:] for?



Best Answer-推荐答案


代码看起来不错,所以我怀疑它是一个不完整的字体实现。

关于ios - UITableViewCell 显示混合字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9813056/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4