开发者

iPhone colorize UILabel substrings

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 wou开发者_Python百科ld 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜