String with attributes Nsmutableattributedstring/nsattributedstring

Source: Internet
Author: User

Since iOS7 new Nstextstorge is a subclass of nsmutableattributedstring, use good nstextstorage, First of all, to learn nsmutableattributedstring and nsattributedstring.

As a personal understanding, nsattributedstring is a string with attributes that gives you the flexibility to manipulate and render multiple styles of literal data.


Alignment//Alignment
Firstlineheadindent//First line Indent
Headindent//Indent
Tailindent//Trailing indent
Linebreakmode//Break method
Maximumlineheight//MAX row height
Minimumlineheight//Minimum row height
LineSpacing//Line spacing
Paragraphspacing//Segment Distance
Paragraphspacingbefore//Segment head space
Basewritingdirection//sentence direction
Lineheightmultiple//variable row height, multiply factor.
Hyphenationfactor//Hyphen Property
NSString *const nsforegroundcolorattributename;//value is uicolor, font color, default is black.


NSString *const nsbackgroundcolorattributename;//value is uicolor, font background color, default is not.


NSString *const nsligatureattributename;//value is integer nsnumber, hyphenation properties, general Chinese can not be used, in English may appear in the case of adjacent letters pen. 0 is not a pen, 1 is the default pen, and the default value, 2 is not supported on iOS.


NSString *const nskernattributename;//value is a floating-point number NSNumber, the Kerning property, the default value is 0.


NSString *const nsstrikethroughstyleattributename;//value is integer nsnumber, the desired value is


enum {


Nsunderlinestylenone = 0x00,


Nsunderlinestylesingle = 0x01,


}; Set strikethrough.


NSString *const nsunderlinestyleattributename;//Ibid. Sets the underline.


The NSString *const nsstrokecolorattributename;//value is Uicolor, the default value is nil, and the property set is the same as Foregroundcolor.


NSString *const nsstrokewidthattributename;//value is a floating-point number nsnumber. Sets the thickness of the drawing.


NSString *const nsshadowattributename;//value is Nsshadow, sets the shadow of the picture, and the default value is nil.


NSString *const nsverticalglyphformattributename;//value for integer nsnumber,0 is the horizontal layout of the word, 1 is the vertical typesetting of the word.


Example code:

Add Strikethrough on label

<span style= "Font-family:comic Sans ms;font-size:18px;" >    UILabel * label = [[UILabel alloc]initwithframe:cgrectmake (+, +, +)];
    
    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 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.