tableviewcell中的归属字符串在单元格出列并重新加载之前不显示粗体文本 [英] Attributed string in tableviewcell not showing bold text until the cell is dequeued and reloaded

查看:101
本文介绍了tableviewcell中的归属字符串在单元格出列并重新加载之前不显示粗体文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表格视图,其中单元格的标签带有一些属性文本。正在从 cellForRowAtIndexPath 中正确设置文本。正确设置了文本的颜色,但在单元格出列之前,不会显示粗体属性。

I have a table view, in which the cells have a label with some attributed text. The text is being set correctly from cellForRowAtIndexPath. The color of the text is being correctly set but the bold attribute is not being displayed until the cell is dequeued.

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
        MyCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier];
        Model *model = [self.fetchedResultsController objectAtIndexPath:indexPath];
        cell.tag = indexPath.row;
        [cell updateContentWithModel:model atIndexPath:indexPath];
        return cell;
}


- (void)updateContentWithModel:(Model *)model atIndexPath:(NSIndexPath *)indexPath
{
self.model = model;
[self setTextFromModel];
[self setImageFromModelAtIndexPath:indexPath];
}

- (void) setTextFromModel
{
self.title.text = self.model.header;
self.status.attributedText = [self boldString:self.model.status fontSize:self.status.font.pointSize color:[UIColor redColor]];
}

+(NSMutableAttributedString *)boldString:(NSString *)stringToBold fontSize:(CGFloat)fontSize color:(UIColor *)color
{
NSMutableAttributedString *boldString = [[NSMutableAttributedString alloc] initWithString:stringToBold];
[boldString setAttributes:@{NSForegroundColorAttributeName: color,
                            NSFontAttributeName:[UIFont boldSystemFontOfSize:fontSize]} range:NSMakeRange(0, boldString.length)];
return boldString;
}

有没有人经历过这样的事情?

Has anyone experience something like this before?

推荐答案

由于UIAppearance,我有同样的问题。在设置UILabel属性文本之前,将font\color设置为nil。

I have same problem due to UIAppearance. Set font\color to nil before setting UILabel attributed text works for me.

这篇关于tableviewcell中的归属字符串在单元格出列并重新加载之前不显示粗体文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆