(If you need not to use the value of the property as a newline, you can write the corresponding property in the program and then press "command" + left mouse button Click to see all the property values)
A label basic settings
Self.view.backgroundColor = [Uicolor Redcolor];
Create a first Label control
UILabel *label = [[UILabel alloc]initwithframe:cgrectmake (50, 50, 200, 30)];
On location settings
To set the center point of a control
Label.center = Self.view.center;
Label.frame = CGRectMake (20, 20, 30, 30);
Display text
Label.text = @ "I am a beauty";
Set Font size
Label.font = [Uifont systemfontofsize:30];
The size of the adaptive size of the method label is determined by the size length of the font
[Label SizeToFit];
The color of the font alpha transparency 0-1 0-1
Label.textcolor = [Uicolor colorwithred:0/255.0 green:0/255.0 blue:195/255.0 alpha:1];
Red Green Blue 0-255 255 255 255
0-1
The font alignment format to the right is the enum type
Label.textalignment = Nstextalignmentcenter;
Add background color
Label.backgroundcolor = [Uicolor Greencolor];
Show the label on the view to display it
[Self.view Addsubview:label];
Addsubview Adding a child view
is not a problem with the program crash premise:
Is the 1th frame set
The 2nd is not added to the parent view
The 3rd background color is the same as the control color
Two. Text self-adapting
Create a label
UILabel *label = [[UILabel alloc]initwithframe:cgrectmake (0, 50, 200, 999)];
Label.backgroundcolor = [Uicolor Greencolor];
Label.text = @ "to being or not to being, that is a question. To was or not to being, which is a question. To was or not to being, which is a question. To was or not to being, which is a question. To was or not to being, which is a question. ";
Label.font = [Uifont systemfontofsize:18];
Label.textcolor = [Uicolor Redcolor];
To set the wrap mode for a label
Label.linebreakmode = nslinebreakbywordwrapping; Line breaks based on words
Set label to display several lines with unlimited lines
Label.numberoflines = 0;
[Label SizeToFit];
[Self.view Addsubview:label];
Iosioslabel Basic use and text adaptive