Objective
As we all know, the UIButton button is the most commonly used control in iOS development, and as a basic learning tutorial for iOS, beginners need to understand their basic definitions and common settings to be proficient in development.
One, iOS set UIButton font size
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 a future SDK version
//should be used
Btn.titleLabel.font = [Uifont systemfontofsize:14.0];
[Btn sebackgroundcolor: [Uicolor Bluecolor]];
Finally, add the button to the specified view Superview
[Superview addsubview:btn];
Second, the iOS settings UIButton text display location
Tvnamelabel=[[uibutton Alloc]initwithframe:cgrectmake (5,5,200,40)];
So initialized, the button
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
There are times when we want to get UIButton
title
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.
Third, iOS set UIButton font color
Set the color of the font on the UIButton
color set on the font UIButton
, not by:
[Btn.titlelabel Settextcolor:[uicolorblackcolor]];
Btn.titlelabel.textcolor=[uicolor Redcolor];
But by:
[Btn Settitlecolor:[uicolor Blackcolor]forstate:uicontrolstatenormal];
Summarize
This is the full content of this article, I hope you can help iOS developers, if you have questions you can message exchange.