在 UITableView 单元格 iOS Swift 中突出显示搜索结果

2024-02-08

我已经实现了一个搜索栏TableView。现在我想强调一下结果。例如,如果我输入了两个字母,那么这两个字母应该在结果中突出显示TableView从搜索栏下拉。谁能帮我做到这一点?我知道我应该为此使用自定义单元格,但我失去了实现它的能力。


Here is the second way to attribute text in tableview

   let initialtext =   "Hello World"
    let attrString: NSMutableAttributedString = NSMutableAttributedString(string: initialtext)

let range: NSRange = (initialtext as NSString).rangeOfString(("World" , options:NSStringCompareOptions.CaseInsensitiveSearch])


    attrString.addAttribute(NSForegroundColorAttributeName, value: UIColor.redColor(), range: range)


    cell!.textLabel?.attributedText = attrString
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 UITableView 单元格 iOS Swift 中突出显示搜索结果 的相关文章

随机推荐