Implementation of Ios-nsmutableattributedstring Rich text

Source: Internet
Author: User

Nsmutableattributedstring inherits from the Nsattributedstring (string with attributes) to be able to quickly and easily achieve rich text effect; not much. Direct and code, easy to understand:

(a):

  

(b) Code:

1UILabel *testlabel = [[UILabel alloc]initwithframe:cgrectmake (0, -, [[UIScreen mainscreen] Bounds].size.width, -)];2     3Testlabel.textalignment =Nstextalignmentcenter;4     5nsmutableattributedstring *attributedstr = [[nsmutableattributedstring alloc]initwithstring:@"Monkey, happy Spring Festival!"];6     7 [Attributedstr addattribute:nsfontattributename8      9Value:[uifont systemfontofsize:26.0]Ten       OneRange:nsmakerange (2,2)]; A      - [Attributedstr addattribute:nsforegroundcolorattributename -       the Value:[uicolor Redcolor] -       -Range:nsmakerange (2,2)]; -      + [Attributedstr addattribute:nsbackgroundcolorattributename -       + Value:[uicolor Redcolor] A       atRange:nsmakerange (7,2)]; -      -Testlabel.attributedtext =Attributedstr; -      -[Self.view Addsubview:testlabel];

(c) Common attributes and descriptions:

Nsfontattributename// font

Nsparagraphstyleattributename// paragraph format

Nsforegroundcolorattributename// font Color

Nsbackgroundcolorattributename// background color

Nsstrikethroughstyleattributename// strikethrough format

Nsunderlinestyleattributename// underline format

Nsstrokecolorattributename// strikethrough color

Nsstrokewidthattributename// Strikethrough width

Nsshadowattributename// shadow

(d) Official Apple Documentation:

https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/ Nsmutableattributedstring_class/index.html

(The above is related to the relevant knowledge of the introduction and understanding, but also hope that we complement each other to improve together)

Implementation of Ios-nsmutableattributedstring 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.