以不同方式格式化UILabel中的文本 [英] Formatting text within UILabel differently
问题描述
我希望UILabel中的不同单词是不同的颜色。这是否意味着每个单词都需要是一个不同的UILabel?我猜是的,虽然肯定会很好地将颜色代码放在标签上,你知道吗?我想我有点被HTML中的文本标记所破坏。
I'd like different words in a UILabel to be different colors. Does this mean each word will need to be a different UILabel? I'm guessing yes, though sure would be nice to just put color codes in the label somehow, you know? I guess I'm a bit spoiled by text markup in HTML.
推荐答案
没有正确的 UIRichTextView iOS中的
。它在我的iOS 6愿望清单上很高(并且有一些理由相信我们可能会因为发布Pages而得到它。)
There is no proper UIRichTextView
in iOS. It's high on my wish-list for iOS 6 (and there's some reason to believe we may get it then due to the release of Pages).
您的选择是使用多个 UILabel
views, NSString UIKit Additions ,核心文本, UIWebView
,或者是少数第三方框架之一,例如:
Your options are to use multiple UILabel
views, NSString UIKit Additions, Core Text, UIWebView
, or one of a few third-party frameworks such as:
- NSAttributedString -Additions-for-HTML
- CoreTextWrapper
- OHAttributedLabel
- OmniUI
- NSAttributedString-Additions-for-HTML
- CoreTextWrapper
- OHAttributedLabel
- OmniUI
所有当前的解决方案都有不同的问题。最常见的问题是,除非您使用Web视图,否则很难获得选择和复制功能以使用富文本。 Web视图非常令人讨厌,因为它们是异步的,您必须在JavaScript中进行大量的交互。
All of the current solutions have different problems. The most common problem is that it's hard to get select and copy functionality to work with rich text unless you use a web view. Web views are incredibly annoying because they're asynchronous and you have to do a lot of your interactions in JavaScript.
我希望有更好的答案。
(强制先令: iOS 5编程的第18章深入讨论了这个主题推动限制。)
这篇关于以不同方式格式化UILabel中的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!