ios - UITableViewCell 显示混合字体

标签 ios cocoa-touch uitableview

由于某种原因,我的 UITableViewCell 显示了混合字体。下面的屏幕截图演示了我的意思:

Mixed fonts on a single UITableViewCell

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

这是我设置字体的代码:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)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?

最佳答案

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

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

相关文章:

ios - 在 iOS 中强制关闭应用程序时处理像 whatsapp 这样的通知?

objective-c - 格式化 float 以填充前导空格

ios - UITableViewCell 内的自定义配件 View 不可见

ios - - (UITableViewCell *)tableView :(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath is not being called

iphone - 在基于导航的应用程序中加载 UITableView 时出现问题

ios - UILabel IOS Swift 中的动画值

objective-c - UITableView reloadData 导致 UITextField resignFirstResponder

ios - 在 iOS 中正确访问 ViewController 中的核心数据上下文

objective-c - 显示导航栏时 viewWillAppear 中的正确 self.view.frame

objective-c - 使用 NSURLConnection 串行发出异步请求