在xcode/iphone中的一个句子中有多种颜色字体
我想在我的 iPhone 应用程序中实现一个功能,执行与此类似的操作。 1 个句子中有 2 种不同颜色的字体。我在堆栈溢出的某个地方读到了大约三个 20,但是三个 20 在我的应用程序上不起作用。我还读过一些有关 textview 的内容?但我尝试阅读相关文档,但我不太明白。
有人有一些示例代码或任何其他建议吗?
谢谢!
I want to implement a feature in my iphone app that does something similar to this. To have 2 different color fonts in 1 sentence. I read somewhere on stack overflow about three 20, but three 20 won't work on my app. I also read something about textview? but I tried to read the documentation for that, but i didn't really understand.
Anyone have some sample code or any other suggestions??
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
TTTAttributedLabel 是 UILabel 的直接替代品,它可以让您应用多种字体、颜色和样式单个标签。您所需要做的就是传入一个 NSAttributedString !它绝对比加载像 Three20 这样巨大的东西或使用 UIWebView 更容易、更高效。
TTTAttributedLabel is a drop-in replacement for UILabel that will let you have multiple fonts, colors, and styles applied to a single label. All you need to do is pass in an NSAttributedString! It's definitely a lot easier and more performant than loading in something gigantic like Three20 or using a UIWebView.
看看 NSAttributedString 类。
编辑:SO 上有一些帖子提供了使用此类的一些指导。 此处可以找到这样一个示例。
这有帮助吗?
Take a look at the NSAttributedString class.
EDIT: There are a few posts on SO that provide some guidance in using this class. One such example can be found here.
Does that help?
GitHub 上有一些 NSAttributedString 开源项目允许此类操作。
在 NSAttributed 字符串可用之前,我们都使用 UIWebView 和“样式化”HTML 来实现相同的效果。这可能是一个选择,具体取决于您的最终需求。
There are a few NSAttributedString OpenSource projects on GitHub that allow this sort of thing.
Before NSAttributed string was available we all used a UIWebView and "styled" HTML to achieve the same affect. This may be an option depending on your final needs.