Nsfontattributename set font properties, default: Font: Helvetica (Neue) font size: 12//nsforegroundcolorattributenam Set Font color, value is Uicolor object, default value is black//Nsbackgroundcolorattributename sets the background color of the font area, the value is Uicolor object, the default value is nil, transparent color//Nsligatureattributename Set the conjoined property to a value of NSNumber object (integer), 0 for no conjoined characters, 1 for the default conjoined character//Nskernattributename to set the character spacing, and a value of NSNumber object (integer number), positive spacing widened, negative spacing narrowed//Nsstrikethroughstyleattributename set Strikethrough, value is NSNumber object (integer)//Nsstrikethroughcolorattributename Set strikethrough color, value to Uicolor object, default to Black//Nsunderlinestyleattributename set underline, value to NSNumber object (integer), enumeration constant Nsunderlinestyle value, and strikethrough Similar//Nsunderlinecolorattributename set the underline color, the value is Uicolor object, the default value is black//Nsstrokewidthattributename Set the stroke width, the value is Nsnu Mber Object (integer), negative fill effect, positive hollow effect//Nsstrokecolorattributename fill part color, not font color, value is Uicolor object//Nsshadowattributename Set the Shadow property, the value is Nsshadow object//Nstexteffectattributename set the text special effect, the value is NSString object, currently only the plate printing effect is available://Nsbaselineoffs Etattributename set the baseline offset value, takeValue NSNumber (float), positive offset, negative bias//Nsobliquenessattributename set glyph tilt, value NSNumber (float), positive right, negative left//Nsexpansionatt Ributename set text stretch properties, value nsnumber (float), positive values stretch text horizontally, negative horizontal compressed text//Nswritingdirectionattributename set Text direction, left to right book Write or right-to-left writing//Nsverticalglyphformattributename Setting the text layout direction, taking value as NSNumber object (integer), 0 for horizontal text, 1 for vertical text//Nslinkattributename Set the link properties, click on the Call browser to open the specified URL address//Nsattachmentattributename settings text attachment, the value is Nstextattachment object, commonly used in text picture mixed//Nsparagrap Hstyleattributename set the text paragraph layout format, the value is Nsparagraphstyle object
[OBJC]View PlainCopy
- Build a small text to test
- UILabel * label = [[UILabel alloc] initwithframe:[uiscreen mainscreen]. Bounds];
- Label. Font = [Uifont systemfontofsize:30];
- Label. textalignment = Nstextalignmentcenter;
- Label. NumberOfLines = 0;
[OBJC]View PlainCopy
- nsmutableattributedstring * Attributedtext = [[nsmutableattributedstring alloc] initwithstring:@ "Test text: \ n Change the text spacing \ n Change the text size \ n Change the text color \ n change the text background \ n Add a text strikethrough \ n add text underline \ n set font tilt \ n Set text flattening "];
- Change text spacing
- [Attributedtext setattributes:@{nskernattributename:@10} Range:nsmakerange (6, 6)];
- Change Text Size
- [Attributedtext setattributes:@{nsfontattributename:[uifont systemfontofsize:30]} range: Nsmakerange (13, 6)];
- Change text color
- [Attributedtext setattributes:@{nsforegroundcolorattributename: [Uicolor Redcolor]} range: Nsmakerange (20, 6)];
- Change text color
- [Attributedtext setattributes:@{nsbackgroundcolorattributename: [Uicolor Yellowcolor]} range: Nsmakerange (27, 6)];
- Add text Strikethrough (Nsunderlinestylesingle is an enumeration, try it out in detail)
- [Attributedtext setattributes:@{nsstrikethroughstyleattributename:@ (nsunderlinestylesingle)} range: Nsmakerange (34, 7)];
- Add text underline (Nsunderlinestylesingle is an enumeration, try it out in detail)
- [Attributedtext setattributes:@{nsunderlinestyleattributename:@ (Nsunderlinestylethick)} range: Nsmakerange (42, 7)];
- Set Font skew
- [Attributedtext setattributes:@{nsobliquenessattributename:@0. 5} Range:nsmakerange (50, 6)];
- Set text flattening
- [Attributedtext setattributes:@{nsexpansionattributename:@0. 4} Range:nsmakerange (57, 7)];
- Font Bold
- [Attributedtext setattribute:nsexpansionattributename value:@(0.5) range:Range];
- Text Assignment after change
[OBJC]View PlainCopy
- Label. Attributedtext = Attributedtext;
- [self. View Addsubview:label];
Official API Reference Link: Https://developer.apple.com/documentation/foundation/nsmutableattributedstring#//apple_ref/doc/uid/ TP40003689 Loading HTML tag text link: http://blog.csdn.net/u010330109/article/details/51882122
IOS Rich Text