IOS nsmutableattributedstring Simple to use

Source: Internet
Author: User

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

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.