// button.titleLabel.textAlignment = NSTextAlignmentLeft; 這句無(wú)效
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
button.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
這里使用
button.titleLabel.textAlignment = NSTextAlignmentLeft; 這行代碼是沒(méi)有效果的,這只是讓標(biāo)簽中的文本左對(duì)齊,但
并沒(méi)有改變標(biāo)簽在按鈕中的對(duì)齊方式。
所以,我們首先要使用
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; 這行代碼,把按鈕的內(nèi)容(控件)
的對(duì)齊方式修改為水平左對(duì)齊,但是這們會(huì)緊緊靠著左邊,不好看,
所以我們還可以修改屬性:
button.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
這行代碼可以讓按鈕的內(nèi)容(控件)距離左邊10個(gè)像素,這樣就好看多了