Two-UILabel Usage summary of iOS development series

Source: Internet
Author: User

Initialize tag UILabel *label = [[UILabel alloc] Initwithframe:cgrectmake (10, 100, 300, 150)];//set label text Label.text = @ "This is a T EST text. This is a test text. This is a test text. "; /Set Label text font//use system font Label.font = [uifont systemfontofsize:20];//use system font Bold//label.font = [Uifont boldsystemfontofsize:20] ;//Specify Font//label.font = [Uifont fontwithname:@ "Arial" size:20];//set label text color Label.textcolor = [Uicolor redcolor];// Set Label background color Label.backgroundcolor = [Uicolor clearcolor];//set Label text alignment label.textalignment = nstextalignmentcenter;// IOS7 Chinese text alignment in the following ways://enum {//Nstextalignmentleft = 0, left-aligned, default//Nstextalignmentcenter = 1, center-aligned/ /nstextalignmentright = 2, right-justified//nstextalignmentjustified = 3, natural alignment at the last line of a paragraph//nstextalignmen Tnatural = 4, default alignment//} nstextalignment;//setting label text auto-wrapping Method Label.linebreakmode = nslinebreakbywordwrapping;//Enum { nslinebreakbywordwrapping = 0, displayed in words as display units, followed by ellipsis not shown, default//nslinebreakbycharwrapping, display units in charactersDisplay, the latter part omitted does not show//nslinebreakbyclipping, cut the content length same as the text width, the latter part is deleted//Nslinebreakbytruncatinghead, the beginning is omitted , display the trailing text content//Nslinebreakbytruncatingtail, end omitted, display the beginning of the text content//Nslinebreakbytruncatingmiddle middle omitted, display the text content of the head and tail /} nslinebreakmode;//sets the number of lines of label text, 0 means multiple lines label.numberoflines = 0;//set shadow color [Label Setshadowcolor:[uicolor blackcolor]];//settings Shadow offset [Label Setshadowoffset:cgsizemake (-1,-1)];//change the spacing between letters to fit the label size label.adjustsletterspacingtofitwidth = no;// Set the font size to fit the label width label.adjustsfontsizetofitwidth = yes;//If the Adjustsfontsizetofitwidth property is set to YES, This property controls the behavior of the text baseline label.baselineadjustment = uibaselineadjustmentnone;//text baseline type has the following types://typedef enum {//Uibaseline Adjustmentalignbaselines, top of text aligns with midline, default//uibaselineadjustmentaligncenters, text midline aligns with label centerline//Uibaselineadju Stmentnone, the bottom of the text is aligned with the label Centerline//} uibaselineadjustment;//settings can interact with the user label.userinteractionenabled = yes;//Set the label text Variable, default = yeslabel.enabled = no;//Set label border Label.layer.borderColor= [[Uicolor graycolor] cgcolor];//set border weight label.layer.borderWidth = 2;//Multiline Label height adaptive//Set Label font properties Nsdictionary * Labelattributes = [Nsdictionary dictionarywithobjectsandkeys:[uifont systemfontofsize:20], NSFontAttributeName, nil] ;//Gets the label based on the height of the text and font adaptive, where cgsizemake is the maximum outer frame size cgfloat labelheight = [@ ' This is a test text. This is a test text. This is a test text. "Boundingrectwithsize:cgsizemake (280, options:nsstringdrawinguseslinefragmentorigin|) Nsstringdrawingusesfontleading attributes:labelattributes context:nil].size.height;

This article fixed link: http://www.itechzero.com/coding/objective-c/ios-development-series-two-uilabel-usage-summary/, reprint please indicate the source.

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.