UIlabel-Rich Text property

Source: Internet
Author: User
Tags control characters italic font set background truncated zapfino font

1.NSKernAttributeName: @10 adjustment sentence kerning sentence adjustment

2.NSFontAttributeName: [Uifont systemfontofsize:_fontsize] Set font

3.NSForegroundColorAttributeName: [Uicolor redcolor] Set text color

4.nsparagraphstyleattributename:paragraph Setting paragraph Styles

5.NSMutableParagraphStyle *paragraph = [[Nsmutableparagraphstyle alloc] init];

Paragraph.alignment = Nstextalignmentcenter;

6.NSBackgroundColorAttributeName: [Uicolor blackcolor] Set background color

7.NSStrokeColorAttributeName Set the text stroke color, you need to set the stroke width with nsstrokewidthattributename, so that the text can be hollow.

Nsstrokewidthattributename the value corresponding to this property is a NSNumber object (decimal). The value changes the stroke width (relative to the percentage of the font size). The default is 0, which does not change. The positive number only changes the stroke width. Negative numbers also change the stroke and fill width of the text. For example, for common hollow words, this value is typically 3.0.

The two properties of the hollow are also set, and the Nsstrokewidthattributename property is set to an integer, and the text foreground color is no effect.

Effect:

Effect:

8. Nsstrikethroughstyleattributename add strikethrough, strikethrough delete line

Effect:

9. Nsunderlinestyleattributename Add Underline

Effect:

Nsshadowattributename Set the shadow, the individual settings are not so, it must be paired with other properties.

And all three of them, Nsverticalglyphformattributename,nsobliquenessattributename,nsexpansionattributename.

11.NSVerticalGlyphFormAttributeName

The value corresponding to this property is a NSNumber object (integer). 0 indicates horizontal text. 1 indicates vertical text. In IOS, horizontal text is always used, and values other than 0 are undefined.

Effect:

Nsobliquenessattributename set the font tilt. Skew Oblique

Effect:

Nsexpansionattributename Setting text flattening

Effect:

Example:

http://shijue.me/show_text/521c396a8ddf876566000007

Http://www.tuicool.com/articles/zquENb

http://blog.csdn.net/a451493485/article/details/9454695

Http://wiki.eoe.cn/page/iOS_pptl_artile_28190.html

Http://www.xue5.com/Mobile/iOS/673562.html

#import "ViewController.h"#import <coretext/coretext.h>@Interface Viewcontroller () @end @implementation viewcontroller-(void) viewdidload{[Super Viewdidload];Learning content/* 1. Control UIView UILabel Uitextfield uitextview UIButton 2. Font, size, unit, color */UILabel *label = [[UILabel alloc] Initwithframe:cg Rectmake (10,30,300,260)]; Label.text =@ "Label text Content, this is a text Label things attribute";The default is null Label.font = [Uifont systemfontofsize:17];The default uses the system's Label.textcolor = [Uicolor Orangecolor];The default is to use text black Label.shadowcolor = [Uicolor Lightgraycolor];Default no Shadow Label.shadowoffset = Cgsizemake (1,0);The default is an upward shadow (0,-1) label.textalignment = Nstextalignmentcenter;The default is left-justified label.linebreakmode = Nslinebreakbytruncatingtail;Paragraph style, the default is the last truncated tail, with ... ReplaceThe basic data type of the rich text, the property string. Based on this, if the corresponding property is set, the property set above is ignored, and the default is null NSString *string = Label.text;Const CGFloat FontSize =16.0; nsmutableattributedstring *attrstring = [[Nsmutableattributedstring alloc] initwithstring:String]; Nsuinteger length = [String length];Set font Uifont *basefont = [Uifont systemfontofsize:fontsize]; [Attrstring Addattribute:nsfontattributenameValue:basefont Range:nsmakerange (0, length)];Set all fonts Uifont *boldfont = [Uifont boldsystemfontofsize:fontsize]; [Attrstring Addattribute:nsfontattributenameValue:boldfont range:[String rangeofstring:@ "Text"];Set text to a font of four letters in boldSet tilt, need to import coretext uifont *italicfont = getvariationoffontwithtrait (Basefont, kctfonttraititalic); [Attrstring Addattribute:nsfontattributenameValue:italicfont range:[String rangeofstring:@ "Label"];Set color Uicolor *color = [Uicolor Redcolor]; [Attrstring Addattribute:nsforegroundcolorattributenameValue:color range:[String rangeofstring:@ "Content"]; [Attrstring Addattribute:nsbackgroundcolorattributenameValue:[uicolor Bluecolor] range:[String rangeofstring:@ "ENT"];You can set values for these propertiesThe font name has the following:Label.font = [Uifont fontwithname:@ "ARIAL-BOLDITALICMT" size:24]; [Attrstring Addattribute:nsfontattributenameValue:[uifont Fontwithname:@ "Verdana-bolditalic" Size:Range:[]String rangeofstring:@ "Label"]; Label.numberoflines =2; Nsmutableparagraphstyle * style = [[Nsparagraphstyle Defaultparagraphstyle] mutablecopy]; Style.linespacing =10;Increase row Height style.headindent =10;Head indent, equivalent to left padding style.tailindent =-10;Equivalent to right padding Style.lineheightmultiple =1.5;The line spacing is how many times style.alignment = Nstextalignmentleft;Alignment style.firstlineheadindent =20;First Outfit Indent style.paragraphspacing =10;Spacing after a paragraph Style.paragraphspacingbefore =20;spacing prior to paragraph [attrstring addattribute:nsparagraphstyleattributenameValue:style Range:nsmakerange (0, length)]; [Attrstring Addattribute:nskernattributenamevalue:@2 Range:nsmakerange (0, length)];Character Spacing 2pt [attrstring addattribute:nsstrokecolorattributenameValue:[uicolor Bluecolor] range:[String rangeofstring:@ "is"];Set the text stroke color, you need to set the stroke width with nsstrokewidthattributename, so that the text can be hollow [attrstring addattribute:nsstrokewidthattributenamevalue:@2 range:[String rangeofstring:@ "is"];Hollow Word, text border description [attrstring addattribute:nsunderlinestyleattributenamevalue:@ (Nsunderlinestylesingle) range:[String rangeofstring:@ "text"];underline [Attrstring Addattribute:nsunderlinestyleattributenamevalue:@ (Nsunderlinestylethick) range:[String rangeofstring:@ "label"];Thick underline [attrstring addattribute:nsstrikethroughstyleattributenamevalue:@ (Nsunderlinepatternsolid | Nsunderlinestylesingle) range:[String rangeofstring:@ "Things"];Strikethrough [Attrstring Addattribute:nsstrikethroughcolorattributenameValue:[uicolor Bluecolor] range:[String rangeofstring:@ "Things"];Strikethrough Blue label.attributedtext = attrstring; Label.highlightedtextcolor = [Uicolor Redcolor];Sets the text highlighting color to use with highlighted. label.highlighted = NO;Whether the highlighted state is turned on label.enabled = YES;Sets whether the text content is variable label.userinteractionenabled = YES;Sets whether the label ignores or removes user interaction. The default is no label.baselineadjustment = Uibaselineadjustmentnone;If the Adjustsfontsizetofitwidth property is set to Yes, this property controls the behavior of the text baseline.Uibaselineadjustmentalignbaselines=0, by default, aligns the top of the text with the centerline.Uibaselineadjustmentaligncenters, the middle of the text is aligned with the label centerline.Uibaselineadjustmentnone, the lowest end of the text is aligned with the label centerline.; [Self.view Addsubview:label];/* The font name is as follows: Font family:american typewriter font:americantypewriter font:americantypewriter-bold font family:applegothic Font:applegothic font family:arial font:arialmt font:arial-boldmt font:arial-bolditalicmt font:arial-italicmt Font Family:arial rounded MT Bold font:arialroundedmtbold font family:arial Unicode MS font:arialunicodems Font Family:cou RieR font:courier font:courier-boldoblique font:courier-oblique font:courier-bold Font family:courier New Font:couri ERNEWPS-BOLDMT font:couriernewps-italicmt font:couriernewps-bolditalicmt font:couriernewpsmt Font family:db LCD Temp F Ont:dblcdtempblack Font family:georgia font:georgia-bold font:georgia font:georgia-bolditalic font:georgia-italic Fo NT Family:helvetica font:helvetica-oblique font:helvetica-boldoblique font:helvetica font:helvetica-bold Font Family: Helvetica Neue font:helveticaneue font:helveticaneue-bold Font family:hiragino Kaku Gothic * * * W3 font:hirakakupron- W3 Font Family:hiragino Kaku Gothic * * * * * W6 font:hirakakupron-w6 font family:marker Felt font:markerfelt-thin font family:stheiti J font:sth Eitij-medium font:stheitij-light font family:stheiti K font:stheitik-medium font:stheitik-light font family:stheiti S C font:stheitisc-medium font:stheitisc-light font family:stheiti TC font:stheititc-light font:stheititc-medium Font F Amily:times New Roman font:timesnewromanpsmt font:timesnewromanps-boldmt font:timesnewromanps-bolditalicmt font:time SNEWROMANPS-ITALICMT font family:trebuchet MS font:trebuchetms-italic font:trebuchetms font:trebuchet-bolditalic Font : Trebuchetms-bold Font family:verdana font:verdana-bold font:verdana-bolditalic font:verdana font:verdana-italic Fon T Family:zapfino Font:zapfino */Text alignment/* Values for Nstextalignment *//* Nstextalignmentleft left-justified nstextalignmentcenter play align nstextalignmentright right align nstextalignmentjustified justify Nstextalignmentnatural align according to the text attributes displayed */Paragraph style/* linespacing; To increase the line spacing paragraphspacing; Alignment Align the firstlineheadindent; Indent pixel headindent at the beginning of the paragraph; Can adjust the indentation distance of all text, can be used as the left padding use tailindent; You can adjust the indentation distance at the end of the text. It is important to note that the value specified here can be used as the width of the text display, but also as the right padding, depending on the positive negative value of the input: Linebreakmode; Minimumlineheight; Maximumlineheight; For different glyphs and font sizes, we can avoid excessive or narrow conditions by specifying the maximum and minimum line spacing (maximumlineheight and minimumlineheight). Basewritingdirection; Lineheightmultiple; To adjust the line spacing, you can use Lineheightmultiple to change the line spacing multiple paragraphspacingbefore; If the content of the article is divided, you can also specify the paragraph ending distance (paragraphspacing) and the paragraph opening distance (Paragraphspacingbefore): Hyphenationfactor; @property (readwrite,copy,ns_nonatomic_iosonly) nsarray *tabstops Ns_available_ios (7_0); @property (readwrite,ns_nonatomic_iosonly) cgfloat defaulttabinterval Ns_available_ios (7_0); *//* Predefined character attributes for text. If The key is no in the dictionary and then use the default values as described below. The predefined Text property value, if the key is not a dictionary, then use the default value as the following description Nsfontattributename font default is Helvetica 12th nsparagraphstyleattributename paragraph style *//* Uikit_extern nsstring *const Ns_available_ios (6_0); Nsparagraphstyle, default Defaultparagraphstyle uikit_extern nsstring *const nsforegroundcolorattributename NS_ Available_ios (6_0); Uicolor, default Blackcolor uikit_extern nsstring *const nsbackgroundcolorattributename Ns_available_ios (6_0); Uicolor, default nil:no background uikit_extern nsstring *const nsligatureattributename Ns_available_ios (6_0); NSNumber containing integer, default 1:default ligatures, 0:no ligatures uikit_extern nsstring *const NSKernAttribute Name Ns_available_ios (6_0); NSNumber containing floating point value, in points; Amount to modify default kerning. 0 means kerning is disabled. (Note:values other than nil and 0 is unsupported on IOS) Uikit_extern nsstring *const nsstrikethroughstyleattributename Ns_available_ios (6_0); NSNumber containing integer, default 0:no strikethrough uikit_extern nsstring *const nsunderlinestyleattributename NS_ Available_ios (6_0); NSNumber containing intEger, default 0:no underline uikit_extern nsstring *const nsstrokecolorattributename Ns_available_ios (6_0); Uicolor, default nil:same as foreground color uikit_extern nsstring *const nsstrokewidthattributename Ns_available_ios (6_0); NSNumber containing floating point value, in percent of the font point size, default 0:no stroke; Positive for stroke alone, negative for stroke and fill (a typical value for outlined text would is 3.0) Uikit_extern NSSt Ring *const nsshadowattributename Ns_available_ios (6_0); Nsshadow, default Nil:no shadow Uikit_extern nsstring *const nstexteffectattributename Ns_available_ios (7_0); NSString, default nil:no text effect uikit_extern nsstring *const nsattachmentattributename Ns_available_ios (7_0); Nstextattachment, default nil uikit_extern nsstring *const nslinkattributename Ns_available_ios (7_0); Nsurl (preferred) or nsstring uikit_extern nsstring *const nsbaselineoffsetattributename Ns_available_ios (7_0); NSNumber containing floatingPoint value, in points; Offset from baseline, default 0 uikit_extern nsstring *const nsunderlinecolorattributename Ns_available_ios (7_0); Uicolor, default nil:same as foreground color uikit_extern nsstring *const nsstrikethroughcolorattributename Ns_availa Ble_ios (7_0); Uicolor, default nil:same as foreground color uikit_extern nsstring *const nsobliquenessattributename Ns_available_ios (7_0); NSNumber containing floating point value; Skew to being applied to glyphs, default 0:no skew uikit_extern nsstring *const nsexpansionattributename Ns_available_ios (7_ 0); NSNumber containing floating point value; Log of expansion factor to being applied to glyphs, default 0:no expansion Uikit_extern nsstring *const Nswritingdirectionat Tributename Ns_available_ios (7_0); Nsarray of nsnumbers representing the nested levels of writing direction overrides as defined by Unicode Lre, RLE, LRO, and RLO characters. The control characters can be obtained by masking nswritingdirection and NSTEXTWRItingdirection values. Lre:nswritingdirectionlefttoright| Nstextwritingdirectionembedding, rle:nswritingdirectionrighttoleft| Nstextwritingdirectionembedding, lro:nswritingdirectionlefttoright| Nstextwritingdirectionoverride, rlo:nswritingdirectionrighttoleft| Nstextwritingdirectionoverride, Uikit_extern nsstring *const nsverticalglyphformattributename NS_AVAILABLE_IOS (6_0) ; An nsnumber containing an integer value. 0 means horizontal text. 1 indicates vertical text. If not specified, it could follow higher-level vertical orientation settings. Currently on IOS, it's always horizontal. The behavior for any and value is undefined. */Nsparagraphstyle paragraph Styletypedef ns_enum (Nsinteger, Nslinebreakmode) {/* Anything to does with long lines *//For long content or multi-line content processingnslinebreakbywordwrapping = 0,/* Wrap at word boundaries, default *//truncation by inclusion wordnslinebreakbycharwrapping,/* Wrap at character boundaries *//truncation by characternslinebreakbyclipping,/* Simply Clip *//Simple trimnslinebreakbytruncatinghead,/* Truncate at head of line: "... wxyz" *///truncated headnslinebreakbytruncatingtail,/* Truncate at Tail of line: "ABCD ..." *//truncated tailnslinebreakbytruncatingmiddle/* Truncate middle of line: "AB ... YZ "*///Truncate MIDDLE// } Ns_enum_available_ios (6_0);} //Get Italic Uifont * getvariationoffontwithtrait (Uifont *basefont, ctfontsymbolictraits trait) {CGFloat fontSize = [ Basefont Pointsize]; Cfstringref basefontname = (__bridge cfstringref) [Basefont FontName]; Ctfontref Basectfont = Ctfontcreatewithname (Basefontname, FontSize, NULL); Ctfontref Ctfont = ctfontcreatecopywithsymbolictraits (Basectfont, 0, NULL, trait, trait); NSString *variantfontname = Cfbridgingrelease (Ctfontcopyname (Ctfont, Kctfontpostscriptnamekey)); Uifont *variantfont = [Uifont fontwithname:variantfontname size:fontsize]; Cfrelease (Ctfont); Cfrelease (Basectfont); return variantfont;}; -(void) didreceivememorywarning{[Super didreceivememorywarning]; //Dispose of any resources, can be recreated.} @end     

UIlabel-Rich Text property

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.