【发布时间】:2017-05-25 21:10:48
【问题描述】:
我正在尝试在文本中设置超链接。文本出现,但我在文本上找不到链接。任何人都可以在这里帮忙。 我想在 getStartedDict 上设置 我的健康行动计划 的链接。但只显示整个文本,没有任何链接。
let link1 = ["My Health Action Plan"]
var getStartedDict =
["":"Now that you have a glimpse of where you currently are in managing your health, it is time for you to update your Health Action Plan. Use the information in the Health Profile along with the online resources in this portal to help set realistic health goals and to help you work toward better health."]
var linkArray = [[String]]()
override func viewDidLoad(){
super.viewDidLoad()
linkArray.removeAll()
linkArray.append(link1)
CommonUtility.sharedInstance.addBackButton(self)
loadData()
}
//这里我尝试设置链接
if let getStartedText = self.getStartedDict[self.model.label1]?.htmlStringToAttributedString()
{
let aText = getStartedText
let myRange = NSRange(location: 0, length: aText.length)
aText.addAttribute(NSFontAttributeName, value: UIFont.systemFontOfSize(kFontSize), range: myRange)
print(aText)
cell.detail.setLinksForSubstrings(linkArray, withLinkHandler: handler)
}
更新:请参阅评论以获取答案
【问题讨论】:
-
是的,我已经看过了,但确实成功了..你能帮帮我吗
-
你也可以通过这种方法帮助我
-
使用属性字符串将您的文本作为超链接
-
能否发表评论让我了解更多