简体   繁体   中英

iOS Annotated UILabel Design Pattern

A client has asked me to include text in an app, a small portion of which should be hyperlinked, so that when it is clicked on it reveals a further fact about their product.

What is the usual design pattern for this? Hyperlinks seem unsuitable to a phone app environment, but a button seems like it spoils the flow of the text. Any pointers appreciated.

You should use a UIWebView to display that information. Just format some short html to display your text and hyperlink and implement the UIWebViewDelegate in order to get notice when the link os tapped.

Hope this helps.

Cheers!

You can use TTTAttributedLabel component, it accepts NSAttributesString as text, so you can format text in any way you want. Also it handles links in text by himself, making its clickable. To handle hyperlink click you need to implement TTTAttributedStringDelegate protocol. It is a way harder than just impelementing UIWebView (especially NSAttributedString formatting part), but it's much faster.

Note, that TTTAttributedLabel is a 3rd-party component, so you need to get it here: https://github.com/mattt/TTTAttributedLabel

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM