/** * Set line spacing and word spacing * * @param linespace line spacing * @param kern word spacing * * @return Rich Text*/-(Nsmutableattributedstring *) Getattributedstringwithlinespace: (NSString *) Text linespace: (cgfloat) Linespace Kern: (cgfloat) Kern {Nsmutableparagraphstyle* Paragraphstyle = [NsmutableparagraphstyleNew]; //Adjust line spacingparagraphstyle.linespacing=Linespace; Paragraphstyle.alignment=Nstextalignmentleft; Paragraphstyle.linespacing= Linespace;//Set Line spacingParagraphstyle.firstlineheadindent =30.0;//set the first line indentNsdictionary*attridict =@{nsparagraphstyleattributename:paragraphstyle,nskernattributename:@ (Kern)}; Nsmutableattributedstring* Attributedstring =[[Nsmutableattributedstring alloc] Initwithstring:text attributes:attridict]; returnattributedstring;}/** * Rich Text part Font set COLOR * * @param text text * @param highlighttext Set the color of * * * @return Rich Text*/-(Nsmutableattributedstring *) setupattributestring: (NSString *) text highlighttext: (NSString *) Highlighttext {nsrange Hightlighttextrange=[text Rangeofstring:highlighttext]; Nsmutableattributedstring*attributestr =[[Nsmutableattributedstring alloc] initwithstring:text]; if(Hightlighttextrange.length >0) {[Attributestr addattribute:nsforegroundcolorattributename VALUE:[HBPLISTRESOURC Eutil Colorwithname:@"Maincolor"] Range:hightlighttextrange]; [Attributestr addattribute:nsfontattributename value:[uifont boldsystemfontofsize:15.0f] Range:hightlighttextrange]; returnAttributestr; }Else { return[highlighttext copy]; }}
The combination of the two:
/** * Set line spacing, word spacing, and text color * * @param linespace line spacing * @param kern word spacing * @param colortext Set Color text * * @return Rich Text*/-(Nsmutableattributedstring *) Getattributedstringwithlinespace: (NSString *) text linespace: (cgfloat) LineSpace Kern :(cgfloat) Kern Colortext: (NSString *) colortext{Nsmutableparagraphstyle* Paragraphstyle = [NsmutableparagraphstyleNew]; //Adjust line spacingparagraphstyle.linespacing=Linespace; Paragraphstyle.alignment=Nstextalignmentleft; Paragraphstyle.linespacing= Linespace;//Set Line spacingParagraphstyle.firstlineheadindent =30.0;//set the first line indentNsdictionary*attridict =@{nsparagraphstyleattributename:paragraphstyle,nskernattributename:@ (Kern)}; Nsrange Colortextrange=[text Rangeofstring:colortext]; Nsmutableattributedstring*attributestr =[[Nsmutableattributedstring alloc] initwithstring:text]; //Set Text color[attributestr addattribute:nsforegroundcolorattributename value:[hbplistresourceutil Color Withname:@"Maincolor"] Range:colortextrange]; [Attributestr addattribute:nsfontattributename value:[uifont boldsystemfontofsize:15.0f] Range:colortextrange]; [Attributestr addattributes:attridict Range:nsmakerange (0, [text length]); returnattributestr;}
iOS set line spacing and partial text color