简体   繁体   English

iOS注释的UILabel设计模式

[英]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. 您应该使用UIWebView来显示该信息。 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. 只需设置一些简短的html格式即可显示您的文本和超链接,并实现UIWebViewDelegate以便在点击链接时获得通知。

Hope this helps. 希望这可以帮助。

Cheers! 干杯!

You can use TTTAttributedLabel component, it accepts NSAttributesString as text, so you can format text in any way you want. 您可以使用TTTAttributedLabel组件,它接受NSAttributesString作为文本,因此您可以使用任何所需的格式设置文本格式。 Also it handles links in text by himself, making its clickable. 它还可以自己处理文本中的链接,使其可单击。 To handle hyperlink click you need to implement TTTAttributedStringDelegate protocol. 要处理超链接,您需要实现TTTAttributedStringDelegate协议。 It is a way harder than just impelementing UIWebView (especially NSAttributedString formatting part), but it's much faster. 这不仅比实现UIWebView(尤其是NSAttributedString格式化部分)困难,但它要快得多。

Note, that TTTAttributedLabel is a 3rd-party component, so you need to get it here: https://github.com/mattt/TTTAttributedLabel 请注意,TTTAttributedLabel是第三方组件,因此您需要在此处获取它: https : //github.com/mattt/TTTAttributedLabel

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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