String with attributes nsmutableattributedstring/nsattributedstring

Source: Internet
Author: User

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;





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.