iPhone 为 UILabel 子字符串着色

发布于 2024-09-02 02:59:58 字数 222 浏览 2 评论 0原文

我正在解析 twitter rss feed,我只需要显示推文,所以我不需要 MGTwitterEngine。 我已经设置好了,这样我就可以看到完整的推文,这是我唯一希望它为主题标签和网址着色的东西。

所以我需要将字符串分割成不同的子字符串,对主题标签和网址进行着色,然后将其粘合在各种 UILabels 中

是否有更简单的方法来完成此操作? 简而言之,我需要字符串的某些部分的颜色与其他部分不同。

I’m parsing a twitter rss feed, and I just need to show tweets, so I don't need MGTwitterEngine.
I have already set it up so I can see the complete tweet, the only thing I want it to colorize hashtags and urls.

So I would need to slice up the string in different substrings, colorize the hashtags and urls and glue it together in various UILabels

Is there an easier way to accomplish this?
In short I need some parts of a string colored differently than others.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦幻之岛 2024-09-09 02:59:58

这个问题应该回答您的问题: iphone-uilabel -同时包含多种字体的文本

使用两个 UILabel IBOutlet,每个都有一个
不同的格式(字体/颜色/等),如
你想要的..把第二个移过去
第一个基于第一个的位置
某人的文字结束。你可以通过
sizeWithFont:forWidth:lineBreakMode:

或者,您可以子类化
UILabel,自己画文字
绘制矩形。如果你这样做的话,只需
添加一个实例变量来告诉你
一根绳子要画多少根
格式,然后在另一个中绘制其余部分。

This question should answer your question: iphone-uilabel-containing-text-with-multiple-fonts-at-the-same-time

Use two UILabel IBOutlets, each with a
different format (font/color/etc), as
you desire.. Move the second one over
the first based on where the first
one's text ends. You can get that via
sizeWithFont:forWidth:lineBreakMode:

Alternatively, you can subclass
UILabel, and draw the text yourself in
drawRect. If you do it this way, just
add an instance variable to tell you
how much of the string to draw in one
format, and draw the rest in another.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文