Tutorial 1-UILabel label class

Source: Internet
Author: User

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];

 

 

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.