按鈕的文字居右
uibutton
*rightbutton = [[
uibutton
alloc
] initwithframe
:cgrectmake
(rightbuttonx,
0,rightbuttonw , frame.
size
.height
)];
//如果緊緊設定以下**,不會生效
rightbutton.
titlelabel
.textalignment
= nstextalignmentright;
//需要加上這邊這一行
rightbutton.
contenthorizontalalignment
= uicontrolcontenthorizontalalignmentright;
//如果不想讓文字緊貼著邊框,就加上下一行
rightbutton.contentedgeinsets = uiedgeinsetsmake(0,0, 0, 10);
文字和的位置調換
cgrect
rightbuttonframe =
self
.rightbutton
.frame;
self
.rightbutton
.titleedgeinsets
= uiedgeinsetsmake(0
, 0, 0
, 15);
self
.rightbutton
.imageedgeinsets
= uiedgeinsetsmake(0
, rightbuttonframe.
size
.width
- 10, 0
, 0);
如何調整UIButton裡面的文字位置
例子如下 cgrect btnrect cgrectmake 360 0.5f,352 0.5f,107,49 m iknowbtn uibutton alloc initwithframe btnrect m iknowbtn settitle foollocalizedstring 知道了 ni...
UIButton的文字顯示位置
有些時候我們想讓uibutton的title居左對齊,我們設定 btn.textlabel.textalignment uitextalignmentleft 是沒有作用的,我們需要設定 btn.contenthorizontalalignment uicontrolcontenthorizonal...
UIButton文字的顯示位置
專案中需要button文字要不居左顯示,要不居右顯示,在做的時候去這樣設定btn.textlabel.textalignment uitextalignmentleft沒有作用 之後我用他的 contenthorizontalalignment屬性去設定,cancelbtn.contenthoriz...