views:

175

answers:

2

Hi all

Yes, many people are saying about Rich Text in iphone ipad and many knows about NSAttributedString.

But how to use NSAttributedString please??? I searched for much time, no extract clues for this.

I know how to set up a NSAttributedString, then what should I do to display a text on iphone / ipad with rich text??

the official doc says it should be used with Core Text Framework, what does that mean?

Is there any simple ways like

NSAttributedString *str;

.....

UILabel *label;

label.attributedString = str;

Sorry guy, so many questions. Please do help.

+1  A: 

You should take a look at UIAttributedLabel in AliSoftware's Cocoa Classes. It is a subclass of UILabel that draws an NSAttributedString and also provides convenience methods for setting the attributes of an NSAttributedString from UIKit classes.

From the sample provided in the repo:

/**(1)** Build the NSAttributedString *******/
NSMutableAttributedString* attrStr = [NSMutableAttributedString attributedStringWithString:@"Hello World!"];
// for those calls we don't specify a range so it affects the whole string
[attrStr setFont:[UIFont systemFontOfSize:12]];
[attrStr setTextColor:[UIColor grayColor]];
// now we only change the color of "Hello"
[attrStr setTextColor:[UIColor redColor] range:NSMakeRange(0,5)];


/**(2)** Affect the NSAttributedString to the UIAttributedLabel *******/
myAttributedLabel.attributedText = attrStr;
// Use the "Justified" alignment
myAttributedLabel.textAlignment = UITextAlignmentJustify;
// "Hello World!" will be displayed in the label, justified, "Hello" in red and " World!" in gray.
Wes
A: 

well, finally I used Three20

Jack
The above answer is correct though. Code like that and ensure you add the CoreText framework to your linked frameworks.
Max Howell
Thanks, i left the correct answer to Wes
Jack