//設(shè)置文字圖片間距
[self.videoButton.titleLabel setLineBreakMode:NSLineBreakByTruncatingTail];
[self.videoButton.titleLabel setFont:[UIFont systemFontOfSize:14]];
[self.videoButton setTitleColor:UIColorFromRGB(0x525252)
forState:UIControlStateNormal];
self.videoButton.titleEdgeInsets = UIEdgeInsetsMake(0, 5 , 0, 0);
self.videoButton.contentEdgeInsets = UIEdgeInsetsMake(0, 15 , 0 , 15);
_btn.contentHorizontalAlignment =UIControlContentHorizontalAlignmentLeft;
_btn.titleEdgeInsets = UIEdgeInsetsMake(0, 10.0, 0, 0);
如果不設(shè)置內(nèi)容對(duì)齊方式原杂,因?yàn)閮?nèi)容文字有可能包含各類字符航棱,大小不等绿渣,導(dǎo)致一定誤差,圖片和文字之間距離大于5,因?yàn)閮?nèi)容“火星包:亞索嗜血屠殺之亞索嗜血屠殺2”,尾部剛好有個(gè)數(shù)字“2”姜盈,導(dǎo)致不準(zhǔn)確如圖:
所以應(yīng)該在設(shè)置間距前,確定文字對(duì)齊方式
//設(shè)置文字圖片間距
[self.videoButton.titleLabel setLineBreakMode:NSLineBreakByTruncatingTail];
[self.videoButton.titleLabel setFont:[UIFont systemFontOfSize:14]];
[self.videoButton setTitleColor:UIColorFromRGB(0x525252)
forState:UIControlStateNormal];
//不可直接調(diào)整titleEdgedInsets配阵,直接調(diào)整的話會(huì)是不準(zhǔn)的馏颂,要先將按鈕內(nèi)容左對(duì)齊或其他方式對(duì)齊,再進(jìn)行邊距調(diào)整
self.videoButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
self.videoButton.titleEdgeInsets = UIEdgeInsetsMake(0, 5 , 0, 0);
self.videoButton.contentEdgeInsets = UIEdgeInsetsMake(0, 15 , 0 , 15);
不可直接調(diào)整titleEdgedInsets棋傍,直接調(diào)整的話會(huì)是不準(zhǔn)的救拉,要先將按鈕內(nèi)容左對(duì)齊或其他方式對(duì)齊,再進(jìn)行邊距調(diào)整瘫拣。