如果您要寻找的是链接,那么您最好使用 UIWebView,并为其提供一些“自制 HTML”,例如“我的链接”。然后,您可以在 Web 视图的委托中处理 Web 视图上的点击。
Simply put, there's no advanced formatting available in UILabel.
If what you're looking for is a link, then you're better of using an UIWebView, and feed it some "home-made HTML", like "My Link". Then you can handle click on the webview in your webview's delegate.
Or better yet instead of overriding just use the OHAttributedLabel created by Olivier Halligon. He also has support for custom links, and for custom colors for them.
发布评论
评论(4)
子类
UILabel
并重写drawRect
方法,如下所示。下划线将具有与标签相同的文本颜色和文本对齐方式:Subclass
UILabel
and overridedrawRect
method as below. Underline will have thesame text color
andtext alignment
as the label:您可以从
UILabel
继承并重写drawRect
方法:You may subclass from
UILabel
and overridedrawRect
method:简而言之,UILabel 中没有可用的高级格式。
如果您要寻找的是链接,那么您最好使用 UIWebView,并为其提供一些“自制 HTML”,例如“我的链接”。然后,您可以在 Web 视图的委托中处理 Web 视图上的点击。
Simply put, there's no advanced formatting available in UILabel.
If what you're looking for is a link, then you're better of using an UIWebView, and feed it some "home-made HTML", like "My Link". Then you can handle click on the webview in your webview's delegate.
使用属性字符串:
然后覆盖标签 - (void)drawTextInRect:(CGRect)aRect 并以类似以下方式呈现文本:
或者更好的是,不要覆盖,只需使用 OHAttributedLabel 由 Olivier Halligon 创建。他还支持自定义链接及其自定义颜色。
Use an attribute string:
And then override the label - (void)drawTextInRect:(CGRect)aRect and render the text in something like:
Or better yet instead of overriding just use the OHAttributedLabel created by Olivier Halligon. He also has support for custom links, and for custom colors for them.