Jean-Luc Godard Jean-Luc Godard - 9 days ago 6
iOS Question

how to change the color of text in string when I use stringWithFormat function?(iphone)

I am using this in a project,

lblDetail.text =[NSString stringWithFormat:@"%@:%@",lblName.text,lblDetail.text];


in this lblName and lblDetail are both different strings,

Now I want that when I show lblDetail in my view, The text of lblName should be shown in green color.

is this possible ?

I want to do like this

http://imageshack.us/photo/my-images/269/comment2c.png/

Answer

If you need a UILabel that can display some Rich-Text, like a text with the first part in blue and the other in red, you can use my OHAttributedLabel class, which is a subclass of UILabel that uses CoreText to draw NSAttributedStrings. (iOS 3.2+)

It is very simple to use and also provide a category for NSAttribtedString that adds some useful methods, like easily change the style of a range of text without the need to know the CoreText attributes constants.

[EDIT] Sorry I didn't realized that Thomas Wanner already mentioned my class in his answer

Comments