· Uilable is the most basic control of the iphone interface and is used primarily to display textual information.
• Common Properties and methods are:
1. Create
CGRect rect = CGRectMake ( +, +, +);
UILabel *label = [[UILabel alloc] initwithframe:rect];
2, text//set and read content, default to nil
Label.text = @ "text message";//set Content
NSLog (@ "%@", label.text);//Read content
3, TextColor//Set text color, default to black
Lable.textcolor = [Uicolor redcolor];
4, Font//set size, default
Label.font = [Uifont systemfontofsize:20];//? general method
Label.font = [Uifont boldsystemfontofsize:20];//Bold Method
Label.font = [Uifont fontwithname:@ "Arial" size:16];//Specify
Method of Font
//also? A way to import fonts from outside.
5, TextAlignment//Set label text alignment.
label.textalignment = nstextalignmentcenter;
Nstextalignmentleft, Nstextalignmentright.
6, NumberOfLines//tags display up to a maximum number of rows, or 0 for multiple lines.
label.numberoflines = 2;
7, Enabled//only determines the way the label is drawn, set it
No will darken the text, indicating that it is not active, and setting a color value to it is not valid.
label.enable = NO;
8, highlighted//whether highlighting
label.highlighted = YES;
Label.highlightedtextcolor = [Uicolor orangecolor];//Highlight
text color when displayed
9, Shadowcolor//Set shadow color
[Label Setshadowcolor:[uicolor Blackcolor];
10, Shadowoffset//Set shadow offset
[Label Setshadowoffset:cgsizemake ( -1,-1)];
11, Baselineadjustment//If the Adjustsfontsizetofitwidth property is set
set to Yes, this property controls the behavior of the text baseline.
label.baselineadjustment = Uibaselineadjustmentnone;
uibaselineadjustmentalignbaselines = 0, default, the top of the text is aligned 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.
12, autoshrink//whether automatic contraction
Fixed Font Size default, text size does not scale automatically if label width is less than text length
Minimumscalefactor Sets the minimum shrinkage scale, if the label width is less than the text length, the text
Shrinks , shrinks beyond the proportions, and then stops shrinking.
Minimumfontsize Sets the minimum shrink size, if the label width is less than the text length, the text size
decrease, lower than the set font size, no longer decreases. 6.0 were no longer used later.
label.minimumscalefactor = 0.5;
13, Adjustsletterspacingtofitwidth//change the spacing between letters to fit the label size
mylabel.adjustsletterspacingtofitwidth = NO;
14, Linebreakmode//Set the display format when the text is too long
Label.linebreakmode = nslinebreakbycharwrapping; display units in characters
The following section is omitted.
label.linebreakmode = nslinebreakbyclipping; cut in the same width as the text
the second part is removed.
label.linebreakmode = nslinebreakbytruncatinghead; Front part text
to have a. method is omitted, displaying the trailing text content.
label.linebreakmode = nslinebreakbytruncatingmiddle; content in the middle
to have a. The method is omitted, showing the text content of the kinsoku.
Label.linebreakmode = Nslinebreakbytruncatingtail; the contents of the ending section
to have a. Method omitted to display the text content of the header.
Label.linebreakmode = nslinebreakbywordwrapping; display units in words
The following section is omitted.
15. Adjustsfontsizetofitwidth//Set font size to fit label width
label.adjustsfontsizetofitwidth = YES;
16. Attributedtext: Sets the Label property text.
nsstring *text = @ "First";
nsmutableattributedstring *textlabelstr =
[[Nsmutableattributedstring alloc]
Initwithstring:text];
[Textlabelstr
Setattributes:@{nsforegroundcolorattributename:
[Uicolor Lightgraycolor], Nsfontattributename:
[Uifont Systemfontofsize:17]} range:nsmakerange (one,
( Ten)];
label.attributedtext = textlabelstr;
17, Vertical text display each text plus a line break, this is the most convenient and simple implementation.
Label.text = @ "please \ \ \ \ \ \ \ \ \ \ \ \ \ \"
label.numberoflines = [Label.text length];
18, calculate the height of the Uilabel with the font after multiple lines
cgrect bounds = CGRectMake (0, 0, +);
Heightlabel = [MyLabel textrectforbounds:bounds
LIMITEDTONUMBEROFLINES:20]; The frame that calculates the label after 20 lines
NSLog (@ "%f", heightLabel.size.height);
19, Uilabel according to the number of words automatically realize the height of adaptation
UILabel *msglabel = [[UILabel alloc]
initwithframe:cgrectmake (0, 0)];
Msglabel.backgroundcolor = [Uicolor lighttextcolor];
[Msglabel setnumberoflines:0];
msglabel.linebreakmode = uilinebreakmodewordwrap;
Msglabel.font = [Uifont fontwithname:@ "Arial" size:12];
cgsize size = Cgsizemake (290, +);
Msglabel.text = @ "Get the Devicetoken, we can use the WebService service to raise
to a . NET application, where I simply process it, print it directly, and copy it into a. NET application environment so that
use. ";
cgsize Msgsie = [Msglabel.text sizewithfont:fonts
Constrainedtosize:size];
[Msglabel setframe:cgrectmake (290, Msgsie.height)];
20. Gradient Font Label
Uicolor *titlecolor = [Uicolor colorwithpatternimage:[uiimage
imagenamed:@ "Btn.png"];
nsstring *title = @ "Setting";
UILabel *titlelabel = [[UILabel alloc]
initwithframe:cgrectmake (0, 0, ())];
titlelabel.textcolor = Titlecolor;
titlelabel.text = title;
Titlelabel.font = [Uifont boldsystemfontofsize:20];
Titlelabel.backgroundcolor = [Uicolor clearcolor];
[Self.view Addsubview:titlelabel];
[Titlelabel release];
21. Label Add Border
TitleLabel.layer.borderColor = [[Uicolor graycolor] cgcolor];
titleLabel.layer.borderWidth = 2;
IOS Uilabel Detailed 1