【发布时间】:2015-12-29 14:58:04
【问题描述】:
我一整天都面临一个大问题,可能有一个简单的解决方案。我有一个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))
【问题讨论】:
-
你能举个例子吗?
标签: ios swift uilabel nsattributedstring