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