Iosioslabel Basic use and text adaptive

Source: Internet
Author: User

(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

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.