Uilabel Basic Use Method

Source: Internet
Author: User
Tags set background

Label basic use method, 1 Create, 2、 set display content, 3、 set text font or size, 4、 set background color or foreground picture, 5, set font line number or wrap line

uilabel* _label = [[Uilabelalloc]initwithframe:cgrectmake (WIDTHOFTHECOLUMNSHOULDBE * 0.5 + (I *

Set content

_label.text = [NSString stringwithformat:@ "%.1f", ecolumn.grade*100];

Specify font and size

[_labelsetfont:[uifont fontwithname:@ "Helvetica" size:12.0]);

Set Font size

_label.font = [Uifont systemfontofsize:10.0];

Clear background color

_label.backgroundcolor = [Uicolor Clearcolor];

Set font color to red

_label.textcolor = [Uicolor Redcolor];

Center text display

_label.textalignment =nstextalignmentcenter;

Automatic line break setting

_label.linebreakmode =nslinebreakbywordwrapping;

Set number of lines, 0 line Wrap

_label.numberoflines = 0;

Set background picture

Uicolor *color = [Uicolor colorwithpatternimage:[uiimageimagenamed:@ "Itemkaung2.png"]];

[_label Setbackgroundcolor:color];

Set text alignment

_label.textalignment =nstextalignmentleft;

_label.textalignment =nstextalignmentcenter;

_label.textalignment =nstextalignmentright;

To set the vertical or oblique display

_label.transform=cgaffinetransformrotate (ecolumnchartlabel.transform,-m_pi/-4);


Set some text to a different color or font

nsstring* content = [NSString stringwithformat:@ "%@:%@", Prisemodle.sender_name, prisemodle.content];

Cgsize size = [NSString calculatetextheight:content_font giventext:content givenwidth:250];

nsmutableattributedstring *str = [[Nsmutableattributedstring alloc] initwithstring:content];

Set the first 5 words to red

[Str addattribute:nsforegroundcolorattributename value:[uicolor Redcolor] Range:nsmakerange (0,5)];

uilabel* replylable = [[Uilabel alloc] Initwithframe:cgrectmake (5, resizelabely, and Size.Height)];

Set Uilabel text

Replylable.attributedtext = str;



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.