【问题标题】:Bold part of detailTextLabel in UITableViewCellUITableViewCell中detailTextLabel的粗体部分
【发布时间】:2015-05-03 14:53:08
【问题描述】:

当用户搜索期刊时,我想在 UITableViewCell 的 detailTextLabel 中显示期刊的一部分和搜索词加粗。

比如,搜索“今天”

2014 年 1 月 19 日 晴朗而晴朗,今天将是一个......

你今天如何加粗这个词,而不是其余的?

cell.detailTextLabel.text = note.content;

【问题讨论】:

标签: ios uitableview


【解决方案1】:

detailTextLabel 具有 setAttributedText 方法,因此您可以制作一个可以大幅度自定义的属性文本,然后您可以对其进行设置。

NSMutableAttributedString * attributedText = [[NSMutableAttributedString alloc] initWithString:note.content];
        NSRange boldedRange = NSMakeRange(0, 5);//        NSRange range = [displayingContent rangeOfString:self.notesSearchBar.text options:NSCaseInsensitiveSearch];

        [attributedText addAttribute: NSFontAttributeName value:[UIFont fontWithName:@"Helvetica-Bold" size:16.0] range:boldedRange];
        [cell.detailTextLabel setAttributedText: attributedText];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-16
    • 1970-01-01
    • 2012-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多