Ios--uilabel

Source: Internet
Author: User

reprinted from: http://blog.csdn.net/cheneystudy/article/details/8115105

This code dynamically creates a Uilabel and lists the relevant common attributes.

-(void) Viewdidload {

Create Uilabel

UILabel *label1 = [[UILabel alloc] initwithframe:cgrectmake (+, + , 280, )];

Set Background color

Label1.backgroundcolor = [Uicolor graycolor];

Set Tag

Label1. tag = ;

Set Label text

Label1. text = @ "ccbase.net!" ;

Set label text font and font size

Label1. font = [uifont fontwithname:@ "Arial" size: +];

Set text alignment

Label1. textalignment = Uitextalignmentcenter;

There are three ways to align text:

typedef enum {

Uitextalignmentleft = 0, left justified

Uitextalignmentcenter, Center-aligned

Uitextalignmentright, right-aligned

} uitextalignment;

Text color

Label1.textcolor = [Uicolor bluecolor];

how to intercept text beyond the label boundary

Label1. Linebreakmode = uilinebreakmodetailtruncation;

There are 6 types of interception methods:

typedef enum {

Uilinebreakmodewordwrap = 0, with space as the boundary, preserves the entire word

Uilinebreakmodecharacterwrap, preserving the entire character

Uilinebreakmodeclip, until the border .

Uilinebreakmodeheadtruncation, omit to begin, to ... Replace

Uilinebreakmodetailtruncation, omit the end to ... Replace

Uilinebreakmodemiddletruncation, omit the middle, to ... instead, multiple rows are used for the last row

} Uilinebreakmode;

The text text adaptive size

Label1.adjustsfontsizetofitwidth = YES;

When Adjustsfontsizetofitwidth=yes , if the text font is to be scaled down

Baselineadjustment This value controls the baseline position of the text, which is valid only if the number of lines of text is 1

Label1. baselineadjustment = uibaselineadjustmentaligncenters;

There are three different ways

typedef enum {

Uibaselineadjustmentalignbaselines = 0,// default text topmost in label centerline alignment

Uibaselineadjustmentaligncenters,// text alignment in label centerline

uibaselineadjustmentnone,// The lowest end of text to the label centerline

} uibaselineadjustment;

The maximum number of lines of text, with a limit of 0 o'clock

Label1.numberoflines = 2;

Minimum font, number of rows is 1 o'clock, default is 0.0

Label1.minimumfontsize = 10.0;

Text highlighting

Label1. highlighted = YES;

Text is mutable

Label1. enabled = YES;

Remove label background color

Label1.backgroundcolor = [Uicolor Clearcolor];

Text Shadow Color

Label1.shadowcolor = [Uicolor graycolor];

Shadow Size

Label1. Shadowoffset = Cgsizemake (1.0, 1.0);

Whether you can interact with users

label1.userinteractionenabled = YES;

[Self. view Addsubview:label1];

[Super Viewdidload];

}

Ios--uilabel

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.