小编Ana*_*and的帖子

如何在UILabel中选择特定单词(Swift 2.0)?

我一直面临一个大问题,可能整天都有一个简单的解决方案.我有一个UILabel,它包含一个NSAttributedString.我想要一个特定的范围UILabel来进行点播.我不想要任何第三方功能.

这是我的示例代码:

let str = dict["itemName"] as! NSString
range = string.rangeOfString(dict["itemName"] as! String)!
index = string.startIndex.distanceTo(range.startIndex)
attributedString.addAttribute(NSForegroundColorAttributeName, value: color, range: NSRange(location: index, length: str.length))
Run Code Online (Sandbox Code Playgroud)

nsattributedstring uilabel ios swift

0
推荐指数
1
解决办法
2769
查看次数

标签 统计

ios ×1

nsattributedstring ×1

swift ×1

uilabel ×1