IOS Text Attribute Dictionary

Source: Internet
Author: User
<span id="Label3"></p> <blockquote style="margin:0 0 0 40px; border:none; padding:0px"> <p><p>iOS development process believe that you often encounter when you need to give fonts, colors, underscores and other attributes when the parameter is a nsdictionary dictionary</p></p> <p><p>But what are the key values in the dictionary?</p></p> <p><p>Let's summarize what we used to do.</p></p> <p><p><br></p></p> <p><p>First we create one of the simplest, set the font and size</p></p> <p><p>We use it as a nsstring method.</p></p> <p><p></p></p> <p style="margin-top:0px; margin-bottom:0px; font-size:13px; font-family:Menlo"><p style="margin-top:0px; margin-bottom:0px; font-size:13px; font-family:Menlo">-(<span style="color:#bb2ca2">void</span>) drawinrect: (<span style="color:#703daa">cgrect</span>) rect withattributes: (<span style="color:#703daa">nsdictionary</span> *) attrs</p></p>To print a string to the view <p><p></p></p> <p><p></p></p> <pre name="code" class="objc"><pre name="code" class="objc">-(void) drawrect: (cgrect) rect{ self.backgroundcolor=[uicolor whitecolor]; NSString *attrstring [email protected] "hello word"; nsdictionary* attrs [email protected]{nsfontattributename:[uifont fontwithname:@ "americantypewriter" size:30] } ; Add the font size of the text in the dictionary [attrstring drawinrect:cgrectmake (20,120,320,200) withattributes:attrs];}</pre></pre> <br> <br> <p><p></p></p> <p><p>Font Color</p></p> <p><p><br></p></p> <p><p></p></p> <pre name="code" class="objc"><pre name="code" class="objc"> nsdictionary* attrs [email protected]{nsfontattributename:[uifont fontwithname:@ "americantypewriter" size:30],// Text color font size nsforegroundcolorattributename:[uicolor redcolor]//text color };</pre></pre> <br> <br> <p><p></p></p> </blockquote> <blockquote style="margin:0 0 0 40px; border:none; padding:0px"> <blockquote style="margin:0 0 0 40px; border:none; padding:0px"> <br> <br> <p> </p> <p>Effect</p> <p> </p> </blockquote> </blockquote>Two<span style="color:rgb(112,61,170); font-family:Menlo; font-size:13px"><span style="color:rgb(112,61,170); font-family:Menlo; font-size:13px">Nsparagraphstyleattributename</span></span><br> <blockquote style="margin:0 0 0 40px; border:none; padding:0px"> <blockquote style="margin:0 0 0 40px; border:none; padding:0px"> <p>Paragraph format</p> <p> </p> <pre name="code" class="objc">-(void) drawrect: (cgrect) rect{ nsstring *attrstring [email protected] "hello word"; Nsmutableparagraphstyle *paragraph=[[nsmutableparagraphstyle alloc]init]; Paragraph.alignment=nstextalignmentcenter;//center nsdictionary* attrs [email protected]{nsfontattributename:[ Uifont fontwithname:@ "americantypewriter" size:30],//text color font size nsforegroundcolorattributename:[uicolor Redcolor],//text color nsparagraphstyleattributename:paragraph,//paragraph format }; [attrstring Drawinrect:cgrectmake (20,120,320,200) withattributes:attrs];}</pre> <br> <br> <p> </p> <p><br></p> <br> <p> </p> <p>Effect: (center)</p> <p> </p> <p> </p> </blockquote> </blockquote><span style="color:rgb(112,61,170); font-family:Menlo; font-size:13px"><span style="color:rgb(112,61,170); font-family:Menlo; font-size:13px">three, Nsbackgroundcolorattributename</span></span><br> <blockquote style="margin:0 0 0 40px; border:none; padding:0px"> <blockquote style="margin:0 0 0 40px; border:none; padding:0px"> <p style="margin-top:0px; margin-bottom:0px; font-size:13px; font-family:Menlo; color:rgb(112,61,170)">Background color</p> <p><br></p> <p> </p> <pre name="code" class="objc">nsdictionary* attrs [email protected]{nsfontattributename:[uifont fontwithname:@ "americantypewriter" size:30],// Text color font size nsforegroundcolorattributename:[uicolor redcolor],//text color nsparagraphstyleattributename: Paragraph,//paragraph format nsbackgroundcolorattributename:[uicolor bluecolor],//background color };</pre> <br> <br> <p> </p> <p><br></p>Effect: <p><br></p> <p><br></p> <p><br></p> </blockquote> </blockquote>Four<span style="color:rgb(112,61,170); font-family:Menlo; font-size:13px"><span style="color:rgb(112,61,170); font-family:Menlo; font-size:13px">Nsstrokecolorattributename</span></span><br> <blockquote style="margin:0 0 0 40px; border:none; padding:0px"> <blockquote style="margin:0 0 0 40px; border:none; padding:0px"> <p>Set stroke color, need to use with <span style="color:rgb(112,61,170); font-family:Menlo; font-size:13px">nsstrokewidthattributename</span></p> <p> </p> <pre name="code" class="objc"> nsdictionary* attrs [email protected]{nsfontattributename:[uifont fontwithname:@ "americantypewriter" size:30],// Text color font size nsforegroundcolorattributename:[uicolor redcolor],//text color nsparagraphstyleattributename: Paragraph,//paragraph format //nsbackgroundcolorattributename:[uicolor bluecolor],//background color nsstrokewidthattributename: @3,//stroke width nsstrokecolorattributename:[uicolor greencolor],//set stroke color, use with nsstrokewidthattributename, Set this nsforegroundcolorattributename will expire };</pre> <br> <br> <p> <br>Effect:</p> <p> </p> </blockquote> </blockquote>Five<span style="color:rgb(112,61,170); font-family:Menlo; font-size:13px"><span style="color:rgb(112,61,170); font-family:Menlo; font-size:13px">Nsstrikethroughstyleattributename</span></span><br> <blockquote style="margin:0 0 0 40px; border:none; padding:0px"> <blockquote style="margin:0 0 0 40px; border:none; padding:0px"> <p>Delete Line</p> <p> </p> <pre name="code" class="objc"> nsdictionary* attrs [email protected]{nsfontattributename:[uifont fontwithname:@ "americantypewriter" size:30],// Text color font size nsforegroundcolorattributename:[uicolor redcolor],//text color nsparagraphstyleattributename: Paragraph,//paragraph format// nsbackgroundcolorattributename:[uicolor bluecolor],//background color nsstrokewidthattributename: @3,//stroke width nsstrokecolorattributename:[uicolor greencolor],//set stroke color, use with nsstrokewidthattributename, Set this nsforegroundcolorattributename to fail the nsstrikethroughstyleattributename:@1,//strikethrough, the number represents the line width };</pre> <br> <br> <p> <br>Effect:</p> <p> </p> <p> </p> <p><br></p> </blockquote> </blockquote>Six<span style="color:rgb(112,61,170); font-family:Menlo; font-size:13px"><span style="color:rgb(112,61,170); font-family:Menlo; font-size:13px">Nsunderlinestyleattributename</span></span><br> <blockquote style="margin:0 0 0 40px; border:none; padding:0px"> <p><p>Underline</p></p> <p><p></p></p> <pre name="code" class="objc"><pre name="code" class="objc">nsdictionary* attrs [email protected]{nsfontattributename:[uifont fontwithname:@ "americantypewriter" size:30],// Text color font size nsforegroundcolorattributename:[uicolor redcolor],//text color nsparagraphstyleattributename: Paragraph,//paragraph format// nsbackgroundcolorattributename:[uicolor bluecolor],//background color nsstrokewidthattributename: @3,//stroke width nsstrokecolorattributename:[uicolor greencolor],//set stroke color, use with nsstrokewidthattributename, Set this nsforegroundcolorattributename to expire// nsstrikethroughstyleattributename:@1,//strikethrough, number for line width nsunderlinestyleattributename:@ (nsunderlinestylesingle),//underline, The value of an enumeration type, you can try each other };</pre></pre> <br> <br> <p><p></p></p> <p><p></p></p> <p><p>Effect:</p></p> <p><p></p></p> </blockquote>Seven<span style="color:rgb(112,61,170); font-family:Menlo; font-size:13px"><span style="color:rgb(112,61,170); font-family:Menlo; font-size:13px">Nsshadowattributename</span></span><br> <blockquote style="margin:0 0 0 40px; border:none; padding:0px"> <p style="margin-top:0px; margin-bottom:0px; font-size:13px; font-family:Menlo; color:rgb(112,61,170)"><p style="margin-top:0px; margin-bottom:0px; font-size:13px; font-family:Menlo; color:rgb(112,61,170)">Set the shadow, his object is a Nsshadow object</p></p> <p><p><br></p></p> <p><p></p></p> <pre name="code" class="objc"><pre name="code" class="objc"> nsdictionary* attrs [email protected]{nsfontattributename:[uifont fontwithname:@ "americantypewriter" size:30],// Text color font size nsforegroundcolorattributename:[uicolor redcolor],//text color nsparagraphstyleattributename: Paragraph,//paragraph format// nsbackgroundcolorattributename:[uicolor bluecolor],//background color nsstrokewidthattributename: @3,//stroke width nsstrokecolorattributename:[uicolor greencolor],//set stroke color, use with nsstrokewidthattributename, Set this nsforegroundcolorattributename to expire// nsstrikethroughstyleattributename:@1,//strikethrough, number for line width nsunderlinestyleattributename:@ (nsunderlinestylesingle),//underline, value is an enumeration type, you can try the Nsshadowattributename separately : Shadow,//set shadow, Copy as a Nsshadow object };</pre></pre> <br> <br> <p><p></p></p> <span style="color:rgb(112,61,170); font-family:Menlo; font-size:13px"><span style="color:rgb(112,61,170); font-family:Menlo; font-size:13px">Nsshadow</span></span> <p><p></p></p> <pre name="code" class="objc"><pre name="code" class="objc"> Nsshadow *shadow=[[nsshadow alloc]init]; Shadow.shadowblurradius=5;//the blur level of the shadow shadow.shadowcolor=[uicolor Bluecolor];//shadow color shadow.shadowoffset= Cgsizemake (6, 6);//shadow relative to the original offset</pre></pre> <br> <br> <p><p></p></p> <p><p></p></p> <br> <br> <p><p></p></p> <p><p>Effect:</p></p> <p><p></p></p> <p><p><br></p></p> </blockquote>Eight<span style="color:rgb(112,61,170); font-family:Menlo; font-size:13px"><span style="color:rgb(112,61,170); font-family:Menlo; font-size:13px">Nsobliquenessattributename</span></span><br> <blockquote style="margin:0 0 0 40px; border:none; padding:0px"> <p><p>Tilt</p></p> <p><p></p></p> <pre name="code" class="objc">nsdictionary* attrs [email protected]{nsfontattributename:[uifont fontwithname:@ "americantypewriter" size:30],// Text color font size nsforegroundcolorattributename:[uicolor redcolor],//text color N Sparagraphstyleattributename:paragraph,//paragraph Format//nsbackgroundcolorattributename:[uicolor BlueColo R],//background Color Nsstrokewidthattributename:@3,//stroke Width nsstrokecolorattributen Ame:[uicolor Greencolor],//set The stroke color, and nsstrokewidthattributename with the use, set the nsforegroundcolorattributename will be invalid nsstrikethroughstyleattributename:@1,//strikethrough, number represents line width Nsunder linestyleattributename:@ (nsunderlinestylesingle),//underline, value is an enumeration type, you can try each other nsshadowattributename:s Hadow,//set the shadow, copy it to a Nsshadow object nsobliquenessattributename:@1//the degree of tilt};</pre> <br> <br> <p><p></p></p> <br>Effect: <p><p></p></p> <p><p></p></p> <p><p><br></p></p> <p><p>We did the usual stuff, and some of them didn't do the Finishing. Everyone is interested to study, welcome Dabigatran and everyone to Discuss.</p></p> <p><p><span style="color:rgb(54,46,43); font-family:Menlo; font-size:15px; line-height:26px">Apple Development group: 414319235 Welcome to join the Welcome discussion question</span></p></p> </blockquote><p><p><span style="white-space:pre"></span></p></p><p><p><span style="white-space:pre"></span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:13px; font-family:Menlo; color:rgb(112,61,170)"><p style="margin-top:0px; margin-bottom:0px; font-size:13px; font-family:Menlo; color:rgb(112,61,170)"><span style="white-space:pre"></span></p></p><p><p><span style="white-space:pre"></span></p></p><p><p><span style="white-space:pre"></span></p></p><p><p><span style="white-space:pre"></span></p></p><p style="margin-top:0px; margin-bottom:0px; font-size:13px; font-family:Menlo; color:rgb(112,61,170)"><p style="margin-top:0px; margin-bottom:0px; font-size:13px; font-family:Menlo; color:rgb(112,61,170)"><span style="white-space:pre"></span></p></p><p><p><span style="white-space:pre"></span></p></p> <p style="font-size:12px;"><p style="font-size:12px;">Copyright Notice: This article for Bo Master original article, without Bo Master permission not Reproduced.</p></p> <p><p>IOS Text Attribute Dictionary</p></p></span>

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.