contentHorizontalAlignment 屬性淺析


轉載自:http://blog.csdn.net/s0228g0228/article/details/46832285

最近在iOS 7以上總是碰到導航條上左右按鈕距離邊距太大的問題

 

為了解決這個這個問題 特別使用了setImageEdgeInsets 和 

 

使用中碰到的范二的事情總結下:警示他人

 

1.setImageEdgeInsets針對的是UIbutton的setImage方法。如果使用setbackimage方法。則會失效無用。

 

 

 2.btn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft ;//設置文字位置,現設為居左,默認的是居中

[btn setTitle:@“title”forState:UIControlStateNormal];// 添加文字

有些時候我們想讓UIButton的title居左對齊,我們設置

btn.textLabel.textAlignment = UITextAlignmentLeft

是沒有作用的,我們需要設置

btn.contentHorizontalAlignment = UIControlContentHorizonAlignmentLeft;

但是問題又出來,此時文字會緊貼到做邊框,我們可以設置

btn.contentEdgeInsets = UIEdgeInsetsMake(0,10, 0, 0);

使文字距離做邊框保持10個像素的距離。

=======================================================

設置UIButton上字體的顏色設置UIButton上字體的顏色,不是用:

[btn.titleLabel setTextColor:[UIColorblackColor]];

btn.titleLabel.textColor=[UIColor redColor];

而是用:

[btn setTitleColor:[UIColor blackColor]forState:UIControlStateNormal];


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM