Simple use of ios-nsmutableattributedstring

Source: Internet
Author: User

1. Initialization

nsmutableattributedstring *attributedstring = [[Nsmutableattributedstring alloc] initwithstring:@ "YOUR _string"];

There is also an initialization method that assigns a property value to a string directly at initialization time:

ID> *) attrs;

2. Assigning a property value to a string

For example, change the first 4-character font color to red:

[Attributedstring addattribute:nsforegroundcolorattributename Value:[uicolor Redcolor] Range:NSMakeRange (0  3)];

3. Common attribute Names

Nsfontattributename fonts

Nsparagraphstyleattributename paragraph format

Nsforegroundcolorattributename Font Color

Nsbackgroundcolorattributename background Color

Nsstrikethroughstyleattributename Strikethrough formatting

Nsunderlinestyleattributename underline format

Nsstrokecolorattributename Strikethrough Color

Nsstrokewidthattributename Strikethrough width

Nsshadowattributename Shadow

PS: Multiple attributes can be placed in nsdictionary, and the AddAttributes function is used to assign the property value to the string

-(voidID> *) attrs Range: (nsrange) range;

Simple use of ios-nsmutableattributedstring

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.