設置按鈕文字距左


  1. // button.titleLabel.textAlignment = NSTextAlignmentLeft; 這句無效  spa

  2.       button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;  orm

  3.       button.titleEdgeInsets = UIEdgeInsetsMake(01000);  it


這裏使用margin

button.titleLabel.textAlignment = NSTextAlignmentLeft; 這行代碼是沒有效果的,這只是讓標籤中的文本左對齊,但top

並無改變標籤在按鈕中的對齊方式。di


因此,咱們首先要使用標籤

button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; 這行代碼,把按鈕的內容(控件)co

的對齊方式修改成水平左對齊,可是這們會牢牢靠着左邊,很差看,background

因此咱們還能夠修改屬性:像素

button.titleEdgeInsets = UIEdgeInsetsMake(01000);

這行代碼能夠讓按鈕的內容(控件)距離左邊10個像素,這樣就好看多了

相關文章
相關標籤/搜索