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