Set UIButton text to align Left

Source: Internet
Author: User

Self.siteButton.titleLabel.textAlignment = Nstextalignmentleft; That's not possible.

Self.sitebutton.contenthorizontalalignment=uicontrolcontenthorizontalalignmentleft;

[Self.sitebutton setTitle:model.siteStr Forstate:uicontrolstatenormal];

[Self.sitebutton settitlecolor:[uicolor colorwithred:78/255.0 green:189/255.0 blue:182.0/255.0 alpha:1.0] ForState: UIControlStateNormal];

Self.siteButton.titleLabel.font = [Uifont systemfontofsize:12.0f];


Reprinted from: http://blog.csdn.net/chengyingzhilian/article/details/8363855/




Btn.frame = CGRectMake (x, y, width, height);

[BTN Settitle: @ "search" forstate:uicontrolstatenormal];

Set the size of the self on the button

[Btn SetFont: [Uifont systemfontsize:14.0]]; This can be used to set the size of the font, but may be removed in the future SDK version of the change method

should use

Btn.titleLabel.font = [Uifont systemfontofsize:14.0];

[Btn sebackgroundcolor: [Uicolor Bluecolor]];

Finally joins the button to the specified view Superview

[Superview ADDSUBVIEW:BTN];

==========================================================

Tvnamelabel=[[uibutton Alloc]initwithframe:cgrectmake (5,5,200,40)];

This initializes the button, the text default color is white, all if the background is also white, can not see the text,

Btn.contenthorizontalalignment=uicontrolcontenthorizontalalignmentleft;//Set text position, now set to left, default is center

[btn settitle:@ "title" forstate:uicontrolstatenormal];//Add text

Sometimes we want UIButton's title to align to the left, we set

Btn.textLabel.textAlignment = Uitextalignmentleft

is not useful, we need to set

Btn.contenthorizontalalignment = Uicontrolcontenthorizonalignmentleft;

But the problem comes out again, when the text is pressed to make the border, we can set

Btn.contentedgeinsets = Uiedgeinsetsmake (0,10, 0, 0);

Keeps the text distance of 10 pixels from the border.

=======================================================

Set the color of the font on UIButton UIButton the color of the font, not with:

[Btn.titlelabel Settextcolor:[uicolorblackcolor]];

Btn.titlelabel.textcolor=[uicolor Redcolor];

Instead, use:

[Btn Settitlecolor:[uicolor Blackcolor]forstate:uicontrolstatenormal];


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.