Use of UILabel label classes
Knowledge outline
1. What is a label?
2. Basic use of tags
3. common attributes of tags
Knowledge points
1. What is a label?
As shown in the following figure, we often need to display text data on the interface. iOS provides us with a UILabel label class. We can use this class to display text data on our interface.
2. Basic use of tags
// Instance: a text Helloworld is displayed at the top of the screen. // 1. create a UILabel object. You can use this label to display the text UILabel * label = [[UILabel alloc] init]; // 2. set the text information label displayed by the label. text = @ "Hello world"; // 3. to set the position and size, you need to input a CGRect type struct variable // details: when no text is displayed, the label will be truncated. frame = CGRectMake (100,100,100, 30); // Add the label to the window to display [self. window addSubview: label]
3. common attributes of tags
// <2> set the label font // UIFont * font = [UIFont systemFontOfSize: 24]; UIFont * font = [UIFont fontWithName: @ "Arial" size: 24]; label. font = font; // <3> set the color label of the label. textColor = [UIColor blueColor]; // The ratio of the first three parameters to the color. // The alpha transparency value // label. textColor = [UIColor colorWithRed: 0.5 green: 0.25 blue: 0.25 alpha: 1]; // <4> set the text shadow label. shadowColor = [UIColor redColor]; // sets the offset label of the shadow. shadowOffset = CGSizeMake (1, 1); // <5> set text alignment // in ios, lable is essentially a label in a rectangle. backgroundColor = [UIColor greenColor]; label. textAlignment = NSTextAlignmentCenter; // <6> multi-line text display (10 indicates 10 rows at most) // 0 indicates no limit on the number of rows // label. numberOfLines = 0; // <7> set the label to automatically adapt to the displayed text // function: the label automatically adjusts the size of the text according to the size of the text [label sizeToFit];