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

Jean-Luc Godard picture Jean-Luc Godard · Jun 9, 2011 · Viewed 8.2k times · Source

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

Tomas Vana picture Tomas Vana · Jun 9, 2011

If you want to assign different colors (or other style attributes like font and size) to different parts of your string, you might be able to use NSAttributedString and some extensions that support its drawing, e.g. OHAttributedLabel. Unfortunately you won't get any support out of the box in the iOS SDK.