按钮图片label位置修改

//为增加image与titleLabel间的距离

[btn setImageEdgeInsets:UIEdgeInsetsMake(0.0, -10, 0.0, 0.0)];

 [btn setTitleEdgeInsets:UIEdgeInsetsMake(0.0, 10, 0.0, 0.0)];

 

top : 为正数的时候,是往下偏移,为负数的时候往上偏移;

left : 为正数的时候往右偏移,为负数的时候往左偏移;

bottom : 为正数的时候往上偏移,为负数的时候往下偏移;

right :为正数的时候往左偏移,为负数的时候往右偏移;

//左字右图

button.titleLabel.backgroundColor = button.backgroundColor;
button.imageView.backgroundColor = button.backgroundColor;
//在使用一次titleLabel和imageView后才能正确获取titleSize    
CGSize titleSize = button.titleLabel.bounds.size;
CGSize imageSize = button.imageView.bounds.size;
CGFloat interval = 1.0;
    
button.imageEdgeInsets = UIEdgeInsetsMake(0,titleSize.width + interval, 0, -(titleSize.width + interval));
button.titleEdgeInsets = UIEdgeInsetsMake(0, -(imageSize.width + interval), 0, imageSize.width + interval);

//上图下字
button.titleLabel.backgroundColor = button.backgroundColor;
button.imageView.backgroundColor = button.backgroundColor;

CGSize titleSize = button.titleLabel.bounds.size;
CGSize imageSize = button.imageView.bounds.size;
CGFloat interval = 1.0;
    
[button setImageEdgeInsets:UIEdgeInsetsMake(0,0, titleSize.height + interval, -(titleSize.width + interval))];
[button setTitleEdgeInsets:UIEdgeInsetsMake(imageSize.height + interval, -(imageSize.width + interval), 0, 0)];
posted @ 2017-03-28 08:57  昊天科技  阅读(393)  评论(0编辑  收藏  举报