Because the new nstextstorge in ios7 is a subclass of nsmutableattributedstring, to use nstextstorage well, you must first learn nsmutableattributedstring and nsattributedstring.
In my personal understanding, nsattributedstring is an attribute string that allows you to flexibly operate and present text data of multiple styles.
Alignment // alignment
Firstlineheadindent // indent the first line
Headindent // indent
Tailindent // tail indent
Linebreakmode // Line Disconnection Mode
Maximumlineheight // The highest Row Height
Minimumlineheight // The lowest Row Height
Linespacing // line spacing
Paragraphspacing // segment distance
Paragraphspacingbefore // the first space of the field
Basewritingdirection // sentence direction
Lineheightmultiple // variable Row Height, multiplication factor.
Hyphenationfactor // character concatenation attribute
Nsstring * const nsforegroundcolorattributename; // The value is uicolor and the font color is black by default.
Nsstring * const nsbackgroundcolorattributename; // The font background color is set to uicolor. The default value is none.
Nsstring * const nsligatureattributename; // The value is an integer nsnumber, which is a hyphen property. Generally, Chinese characters are not used, and adjacent letters may be written in English. 0 indicates no link; 1 indicates the default link; 2 indicates no link on IOS.
Nsstring * const nskernattributename; // The value is a floating point nsnumber. The default value is 0.
Nsstring * const nsstrikethroughstyleattributename; // The value is an integer nsnumber. The value can be set
Enum {
Nsunderlinestylenone = 0 × 00,
Nsunderlinestylesingle = 0 × 01,
}; Set strikethrough.
Nsstring * const nsunderlinestyleattributename; // same as above. Set the underline.
Nsstring * const nsstrokecolorattributename; // The value is uicolor, the default value is nil, and the set attribute is the same as foregroundcolor.
Nsstring * const nsstrokewidthattributename; // The value is a floating point nsnumber. Set the width of the comparison.
Nsstring * const nsshadowattributename; // set the value to nsshadow and the default value to nil.
Nsstring * const nsverticalglyphformattributename; // The value is an integer nsnumber. 0 indicates a horizontal typographical character, and 1 indicates a vertical typographical character.
Sample Code:
// Add strikethrough on the label
<span style="font-family:Comic Sans MS;font-size:18px;"> UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 100, 100)]; label.text = @"zuoyou1314"; NSMutableAttributedString * str = [[NSMutableAttributedString alloc] initWithString:@"zuoyou1314"]; [str addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInt: NSUnderlineStyleSingle] range:NSMakeRange(0, str.length)]; label.attributedText = str; [self.window addSubview:label];</span>
// Set the underline
NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:@"Some String"]; [attString addAttribute:(NSString*)kCTUnderlineStyleAttributeName value:[NSNumber numberWithInt:kCTUnderlineStyleSingle] range:(NSRange){0,[attString length]}]; self.myLabel.attributedText = attString;