Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to add a hyperlink to certain parts of my text which is being handled and drawn using CoreText.

According to Apple's docs on CoreText I should be using addAttribute:NSLinkAttributeName however on iOS (4.3) it says it doesn't know NSLinkAttributeName. In my document searches it looks like NSLinkAttributeName only still exists on the Mac.

Is it available on iOS and I am just missing something? If it's not available how can I create a hyperlink on part of a text using NSMutableAttributedString and CoreText?

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
599 views
Welcome To Ask or Share your Answers For Others

1 Answer

As of iOS 7, UITextView supports links in attributed strings:

textView.attributedText = [[NSAttributedString alloc] initWithString:@"Stack Overflow" attributes:@{NSLinkAttributeName: @"http://stackoverflow.com"}];

By default, links are rendered as blue text. You can change the style with UITextView's linkTextAttributes property.

If you set editable to NO on the UITextView, links become tappable.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...