[英]UIButton title alignment and multiline support
如何將UIButton
的標題設置為左對齊,以及如何在UIButton
顯示多行文本?
這也是在代碼中進行UIButton對齊的代碼:-
[myButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
要設置UIButton
的對齊UIButton
,請在Interface Builder中的“屬性”檢查器中查找按鈕。 有一個稱為對齊的部分。 將其設置為左側。 或正確,或任何您想要的。
為此,請使用UIControl
的contentHorizontalAlignment
屬性。 您可以將其設置為以下任何屬性:
UIControlContentHorizontalAlignmentCenter
UIControlContentHorizontalAlignmentLeft
UIControlContentHorizontalAlignmentRight
UIControlContentHorizontalAlignmentFill
[myButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
這些選項都沒有一個看起來特別好(如您在上面看到的),使用UIButton
的contentEdgeInsets
屬性來重新定位內容可能會帶來更多的運氣。
要在UIButton
上設置多行標題 , 請查看此論壇帖子 ,其中描述了如何更改按鈕標簽。
或者,您可以使用此代碼快速創建2行按鈕:
myButton.titleLabel.textAlignment = UITextAlignmentCenter;
myButton.titleLabel.lineBreakMode = UILineBreakModeCharacterWrap;
[myButton setTitle:@"Siegfried\nRoy" forState:UIControlStateNormal];
Raju,別忘了將問題標記為已接受。
實際上,您可以將lineBreakMode
設置為UILineBreakModeWordWrap
或UILineBreakModeCharacterWrap
。 如有必要,這會將文本分成多行。
嘗試這個
myButton.titleLabel.textAlignment = UITextAlignmentLeft;
myButton.titleLabel.lineBreakMode = UILineBreakModeCharacterWrap;
myButton.titleLabel.numberOfLines = 0;
要添加段落效果,您可以更改標題的大小。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.