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