ios-text paragraph style nsmutableparagraphstyle and Nsparagraphstyle use and some rich Text processing properties

Source: Internet
Author: User
Tags transparent color vars

In the process of development, we often encounter the problem of dynamic calculation of row height.

-(cgrectcgsize) size options: (nsstringdrawingoptions Options attributes: (nullable nsdictionary <nsstring *, id > *) Attributes Context: (nullable  Nsstringdrawingcontext *) Context ns_available ( Span class= "S3" >10_11, 7_0);

Is the Apple recommended calculation method, obviously encounter paragraph formatting problems, such as line spacing, indentation and other formatting requirements, attributes passed in the dictionary, including our set of fonts and formats, where nsparagraphstyleattributename is set paragraph style, Nsfontattributename is the setting font.

OK, take a look at the function of Nsparagraphstyleattributename.

[OBJC]View PlainCopy
  1. Nsparagraphstyleattributename paragraph style (set first line, line spacing, alignment, etc.) see what you need and write
  2. Nsmutableparagraphstyle *paragraphstyle = [[Nsmutableparagraphstyle alloc] init];
  3. Paragraphstyle. linespacing = 10; Line spacing for fonts
  4. Paragraphstyle. firstlineheadindent = 20. 0f; First line indent
  5. Paragraphstyle. Alignment = nstextalignmentjustified; (justified) Text alignment: (left, middle, right, justified, natural)
  6. Paragraphstyle. Linebreakmode = Nslinebreakbytruncatingtail; The end of the content with ... Way omitted ("... wxyz", "ABCD ...", "AB ... YZ ")
  7. Paragraphstyle. headindent = 20; Overall indent (except for the first row)
  8. Paragraphstyle. tailindent = 20; //    
  9. Paragraphstyle. minimumlineheight = 10; Minimum row height
  10. Paragraphstyle. maximumlineheight = 20; Maximum row height
  11. Paragraphstyle. paragraphspacing = 15; spacing between segments and segments
  12. Paragraphstyle. Paragraphspacingbefore = 22. 0f;  The Blank Space/* Distance between the bottom of the previous paragraph (or the end of its paragraphspacing, if any) and the top of this paragraph. */    
  13. Paragraphstyle. basewritingdirection = nswritingdirectionlefttoright; The direction of writing from left to right (altogether?? Three types)
  14. Paragraphstyle. lineheightmultiple = 15; /* Natural line height are multiplied by this factor (if positive) before being constrained by minimum and maximum line Hei Ght. */    
  15. Paragraphstyle. hyphenationfactor = 1; Hyphenation properties in iOS, the only supported values are 0 and 1, respectively


OK, now it's easy to calculate a paragraph height, for example:

[OBJC]View PlainCopy
  1. _descatt = [[nsmutableattributedstring alloc] initwithstring:_model. Desc];
  2. Uifont *descfont = [Uifont pingfangsc_regular_withsize:12];
  3. Nsmutableparagraphstyle *descstyle = [[Nsmutableparagraphstyle alloc]init];
  4. [Descstyle setlinespacing:1]; Line spacing
  5. Cgsize descsize = [_model. Desc Boundingrectwithsize:cgsizemake (w, maxfloat)
  6. Options:nsstringdrawinguseslinefragmentorigin
  7. Attributes:@{nsfontattributename:descfont,
  8. Nsparagraphstyleattributename:d Escstyle}
  9. context: nil]. Size;


In addition, several properties of rich Text processing are introduced:

[OBJC]View PlainCopy
    1. Nsfontattributename setting font properties, default: Font: Helvetica (Neue) font Size: 12
    2. Nsforegroundcolorattributenam set font color, value to Uicolor object, default value is black
    3. Nsbackgroundcolorattributename set the region background color of the font, the value is Uicolor object, the default value is nil, transparent color
    4. Nsligatureattributename sets the conjoined property, with a value of NSNumber object (integer), 0 for no conjoined character, and 1 for the default conjoined character
    5. Nskernattributename set character spacing, value is NSNumber object (integer), positive spacing is widened, and negative spacing narrows
    6. Nsstrikethroughstyleattributename set Strikethrough, value is NSNumber object (integer)
    7. Nsstrikethroughcolorattributename set strikethrough color, value is Uicolor object, default value is black
    8. Nsunderlinestyleattributename sets an underscore to a value of NSNumber object (integer), enumeration of values in constant Nsunderlinestyle, similar to strikethrough
    9. Nsunderlinecolorattributename sets the underline color, the value is the Uicolor object, the default value is black
    10. Nsstrokewidthattributename Sets the stroke width, takes a value of NSNumber object (integer), negative fill effect, positive hollow effect
    11. Nsstrokecolorattributename fills part of the color, not the font color, and takes the value of the Uicolor object
    12. Nsshadowattributename Set the Shadow property to a value of Nsshadow object
    13. Nstexteffectattributename sets the text special effect, the value is the NSString object, currently only the plate printing effect is available:
    14. Nsbaselineoffsetattributename set the baseline offset value to NSNumber (float), positive offset, negative bias
    15. Nsobliquenessattributename set the Glyph tilt, value NSNumber (float), positive right, negative left
    16. Nsexpansionattributename set text stretch properties, value nsnumber (float), positive values stretch text horizontally, negative values compress text horizontally
    17. Nswritingdirectionattributename setting the direction of writing, writing from left to right or from right to left
    18. Nsverticalglyphformattributename sets the text layout direction, takes a value of NSNumber object (integer), 0 for horizontal text, and 1 for vertical text
    19. Nslinkattributename set the link properties, click on the browser to open the specified URL address
    20. Nsattachmentattributename Set the text attachment, the value is the Nstextattachment object, commonly used in the text picture mixed row
    21. Nsparagraphstyleattributename set the text paragraph layout format, the value is Nsparagraphstyle object

ios-text paragraph style nsmutableparagraphstyle and Nsparagraphstyle use and some rich Text processing properties

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.