1,
// Running Effect
Self. attributestringlabel. attributedtext = [self getattributedstringwithstring: @ "Fu is the font of this attribute" astring: @ "color" astring: @ "underline"];
/**
* Nsmutableattributedstring simple demo Method
*
* @ Param str1 the first property string
* @ Param str2 the first property string
* @ Param str3 the first attribute string
*
* @ Return nsmutableattributedstring
*/
-(Nsmutableattributedstring *) getattributedstringwithstring :( nsstring *) str1 astring :( nsstring *) str2 astring :( nsstring *) str3 {
Nsstring * normalstring = [nsstring stringwithformat: @ "% @ -- % @", str1, str2, str3];
Nsmutableattributedstring * attredstring = [[nsmutableattributedstring alloc] initwithstring: normalstring] autorelease];
// The nsange of each attribute
Nsange range1 = [normalstring rangeofstring: str1];
Nsange range2 = [normalstring rangeofstring: str2];
Nsange range3 = [normalstring rangeofstring: str3];
// Specific attributes in each nsange (all attributes can be queried by nsattributedstring in the uikit Framework)
Nsdictionary * attres1 = [nsdictionary dictionarywithobject: [uifont fontwithname: @ "palatino-Roman" Size: 20366f] forkey: nsfontattributename];
Nsdictionary * attres2 = [nsdictionary dictionarywithobject: [uicolor purplecolor] forkey: nsforegroundcolorattributename];
Nsdictionary * attres3 = [nsdictionary dictionarywithobject: [uicolor redcolor] forkey: nsunderlinecolorattributename];
Nsdictionary * attres4 = [nsdictionary dictionarywithobject: [nsstring stringwithformat: @ "1"] forkey: nsunderlinestyleattributename];
// Set attributes
[Attredstring addattributes: attres1 range: range1];
[Attredstring addattributes: attres2 range: range2];
[Attredstring addattributes: attres3 range: range3];
[Attredstring addattributes: attres4 range: range3];
Return attredstring;
}
2. After ios7, A New Rich Text API can be added through URL and stream
Optional * attredstring1 = [[nsmutableattributedstring alloc] initwithfileurl: <# (nsurl *) #> options: <# (nsdictionary *) #> documentattributes: <# (nsdictionary **) #> error: <# (nserror **) #>]
Optional * attredstring2 = [nsmutableattributedstring alloc] initwithdata: <# (nsdata *) #> options: <# (nsdictionary *) #> documentattributes: <# (nsdictionary **) #> error: <# (nserror **) #>;