IOS Rich Text

Source: Internet
Author: User


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
    1. Build a small text to test
    2. UILabel * label = [[UILabel alloc] initwithframe:[uiscreen mainscreen]. Bounds];
    3. Label. Font = [Uifont systemfontofsize:30];
    4. Label. textalignment = Nstextalignmentcenter;
    5. Label. NumberOfLines = 0;
[OBJC]View PlainCopy
  1. 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 "];
  2. Change text spacing
  3. [Attributedtext setattributes:@{nskernattributename:@10} Range:nsmakerange (6, 6)];
  4. Change Text Size
  5. [Attributedtext setattributes:@{nsfontattributename:[uifont systemfontofsize:30]} range:  Nsmakerange (13, 6)];
  6. Change text color
  7. [Attributedtext setattributes:@{nsforegroundcolorattributename: [Uicolor Redcolor]} range:  Nsmakerange (20, 6)];
  8. Change text color
  9. [Attributedtext setattributes:@{nsbackgroundcolorattributename: [Uicolor Yellowcolor]} range:  Nsmakerange (27, 6)];
  10. Add text Strikethrough (Nsunderlinestylesingle is an enumeration, try it out in detail)
  11. [Attributedtext setattributes:@{nsstrikethroughstyleattributename:@ (nsunderlinestylesingle)} range:  Nsmakerange (34, 7)];
  12. Add text underline (Nsunderlinestylesingle is an enumeration, try it out in detail)
  13. [Attributedtext setattributes:@{nsunderlinestyleattributename:@ (Nsunderlinestylethick)} range:  Nsmakerange (42, 7)];
  14. Set Font skew
  15. [Attributedtext setattributes:@{nsobliquenessattributename:@0. 5} Range:nsmakerange (50,  6)];
  16. Set text flattening
  17. [Attributedtext setattributes:@{nsexpansionattributename:@0. 4} Range:nsmakerange (57, 7)];
  18. Font Bold
  19. [Attributedtext setattribute:nsexpansionattributename value:@(0.5) range:Range];
  20. Text Assignment after change
[OBJC]View PlainCopy
    1. Label. Attributedtext = Attributedtext;
    2. [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

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.