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