iOS set the alignment/size and color of the font on the UIButton

Source: Internet
Author: User

iOS set the alignment/size and color of the font on the UIButton

Set the alignment of the font on the UIButton, not by:

[Paywaybutton.titlelabel Settextalignment:uitextalignmentcenter];

But by:

[Paywaybutton Setcontenthorizontalalignment:uicontrolcontenthorizontalalignmentcenter];

Set the text display position of the UIButton, the font size, the font color

Btn.frame = CGRectMake (x, y, width, height);
[BTN Settitle: @ "search" forstate:uicontrolstatenormal];
Set the size of the self on a button
[Btn setfont: [Uifont systemfontsize:14.0]]; This can be used to set the size of the font, but may be removed in a future SDK version
should use
Btn.titleLabel.font = [Uifont systemfontofsize:14.0];
[Btn sebackgroundcolor: [Uicolor Bluecolor]];
Finally, add 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, the default is centered
[btn settitle:@ "title" forstate:uicontrolstatenormal];//Add text
Sometimes we want UIButton's title to be left-aligned, and we set
Btn.textLabel.textAlignment = Uitextalignmentleft
is not going to work we need to set
Btn.contenthorizontalalignment = Uicontrolcontenthorizonalignmentleft;
But the problem comes out again, the text will cling to the border, we can set
Btn.contentedgeinsets = Uiedgeinsetsmake (0,10, 0, 0);
Keep the text distance from the border by 10 pixels.
=======================================================
Set the color of the font on the UIButton to set the color of the font on the UIButton, not by:
[Btn.titlelabel Settextcolor:[uicolorblackcolor]];
Btn.titlelabel.textcolor=[uicolor Redcolor];
But by:
[Btn Settitlecolor:[uicolor Blackcolor]forstate:uicontrolstatenormal];

Related Article

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.