TTTAttributedLabel addLinkToURL NSRange混淆

时间:2015-01-17 06:52:28

标签: xcode swift hyperlink tttattributedlabel

我正在制作一个快速的应用程序,我想在TTTAttributedLabel中添加一个URL。我有addLinkToUrl但它想要一个NSRange。我应该放什么我是新手。我希望网址是整个文本。

//PersonTalking is a TTTAttributedLabel
        var characterSpeaking:NSDictionary = item["characterspeaking"] as NSDictionary
        var characterSpeakingString:String = characterSpeaking["text"] as String
        var characterHref:String = characterSpeaking["href"] as String
        var characterUrl = NSURL(string: characterHref)
        println(characterSpeakingString)
        PersonTalking.text = characterSpeakingString

        PersonTalking.addLinkToURL(characterUrl, withRange: )

我该怎么办?

由于

1 个答案:

答案 0 :(得分:1)

如果链接包含完整标签,则您的范围应为文字的全长。

PersonTalking.addLinkToURL(characterUrl, 
                           withRange:NSMakeRange(0,
                                                countElements(characterSpeakingString))