iOS上如何讓按鈕文本左對齊問題
// button.titleLabel.textAlignment = NSTextAlignmentLeft; 這句無效 button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; button.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
這裏使用
button.titleLabel.textAlignment = NSTextAlignmentLeft; 這行代碼是沒有效果的,這隻是讓標簽中的文本左對齊,但
並沒有改變標簽在按鈕中的對齊方式。
所以,我們首先要使用
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; 這行代碼,把按鈕的內容(控件)
的對齊方式修改為水平左對齊,但是這們會緊緊靠著左邊,不好看,
所以我們還可以修改屬性:
button.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
這行代碼可以讓按鈕的內容(控件)距離左邊10個像素,這樣就好看多了最後更新:2017-04-03 12:56:21