Nsmutableattributedstring Section Properties Introduction
/** nsfontattributename---Set the font size */
/** nsforegroundcolorattributename---Set font color */
/** nsparagraphstyleattributename---Set paragraph format (no noticeable change) */
/** Nsbackgroundcolorattributename---Set the background color of the font */
/** Nsligatureattributename---Set the conjoined property (no noticeable change) */
/** nskernattributename---Set spacing between characters, integer increase, negative number decrease */
/** nsstrikethroughstyleattributename---set strikethrough */
/** nsstrikethroughcolorattributename---Set the color of the strikethrough */
/** nsunderlinestyleattributename---set underline */
/** nsunderlinecolorattributename---Set the color of the underline */
/** Nsstrokewidthattributename---Set the stroke width to a value of NSNumber object (integer), negative fill effect, positive hollow effect */
/** nsstrokecolorattributename---Fill part of the color, not the font color, the value is Uicolor object */
/** Nsshadowattributename---Set the shadow of the font, the value is Nsshadow object */
NSString *str =@"hahaha, hey, ah oh, https://www.baidu.com, roar and roar, uh-hmm, GAKJFKLJ"; Nsmutableattributedstring*attributestr =[[Nsmutableattributedstring alloc]initwithstring:str]; /** Nsfontattributename---set font size*/[Attributestr addattribute:nsfontattributename value:[uifont boldsystemfontofsize: -] Range:nsmakerange (0,3)]; /** Nsforegroundcolorattributename---set font color*/[Attributestr addattribute:nsforegroundcolorattributename value:[uicolor Redcolor] Range:NSMakeRange (0,3)]; [Attributestr addattribute:nsforegroundcolorattributename Value:[uicolor Bluecolor] Range:NSMakeRange (Ten, +)]; /** Nsparagraphstyleattributename---Set paragraph format (no noticeable change)*/Nsmutableparagraphstyle*style =[[Nsmutableparagraphstyle alloc]init]; Style.headindent= -; [Attributestr addattribute:nsparagraphstyleattributename value:style Range:nsmakerange (0, Attributestr.length)]; /** Nsbackgroundcolorattributename---Set the background color of the font*/[Attributestr addattribute:nsbackgroundcolorattributename value:[uicolor Cyancolor] Range:NSMakeRange (4,2)]; /** Nsligatureattributename---Set the conjoined properties (no noticeable change)*/[Attributestr addattribute:nsligatureattributename value:[nsnumber Numberwithinteger:1] Range:nsmakerange (7,2)]; /** Nskernattributename---Set spacing between characters, integers increase, negative numbers decrease*/[Attributestr addattribute:nskernattributename value:[nsnumber Numberwithinteger:0] Range:nsmakerange (7,1)];//[Attributestr addattribute:nskernattributename value:[nsnumber numberwithinteger:-10] Range:NSMakeRange (7, 1)]; /** Nsstrikethroughstyleattributename---set strikethrough*/[Attributestr addattribute:nsstrikethroughstyleattributename value:[nsnumber Numberwithinteger:1] Range:nsmakerange (Attributestr.length-8,8)]; /** Nsstrikethroughcolorattributename---Set the color of strikethrough*/[Attributestr addattribute:nsstrikethroughcolorattributename value:[uicolor Redcolor] Range:NSMakeRange ( Attributestr.length-8,8)]; /** Nsunderlinestyleattributename---set underline*/[Attributestr addattribute:nsunderlinestyleattributename value:[nsnumber Numberwithinteger: Nsunderlinestylesingle] Range:nsmakerange (Ten, +)]; [Attributestr addattribute:nslinkattributename value:[nsurl urlwithstring:@"HTTPS://WWW.BAIDU.COM/INDEX.PHP?TN=MONLINE_3_DG"] Range:nsmakerange (Ten, +)]; /** Nsunderlinecolorattributename---Set the color of the underline*/[Attributestr addattribute:nsunderlinecolorattributename value:[uicolor Redcolor] Range:NSMakeRange (Ten, +)]; /** Nsstrokewidthattributename---Set stroke width, value is NSNumber object (integer), negative fill effect, positive hollow effect*/[Attributestr addattribute:nsstrokewidthattributename value:[nsnumber Numberwithinteger:1] Range:nsmakerange ( +,4)]; /** Nsstrokecolorattributename---Fill part of the color, not the font color, the value is Uicolor object*/[Attributestr addattribute:nsstrokecolorattributename value:[uicolor Magentacolor] Range:NSMakeRange ( +,4)]; /** Nsshadowattributename---Set the shadow of the font, the value is Nsshadow object*/Nsshadow*shadow =[[Nsshadow alloc]init]; Shadow.shadowcolor=[Uicolor Orangecolor]; Shadow.shadowoffset= Cgsizemake (-2, -2); Shadow.shadowblurradius=2; [Attributestr addattribute:nsshadowattributename Value:shadow Range:nsmakerange (Panax Notoginseng,4)]; Self.richLabel.attributedText= Attributestr;
View Code
IOS nsmutableattributedstring Simple to use