UIButton图文位置设置EdgeInsets

2016-08-03  本文已影响36人  然亦伞

1、 图片在文字右边

CGFloat titleW = showSelectClickBtn.titleLabel.width;

CGFloat imgW = showSelectClickBtn.imageView.width ;

[showSelectClickBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, -imgW, 0, imgW)];

[showSelectClickBtn setImageEdgeInsets:UIEdgeInsetsMake(0, titleW, 0, -titleW)];

2、图片在文字上面

showSelectClickBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;

CGFloat imgHlafW = showSelectClickBtn.imageView.width * 0.5;

CGFloat imgHlafH = showSelectClickBtn.imageView.height * 0.5;

CGFloat titleHlafW = showSelectClickBtn.titleLabel.width * 0.5;

CGFloat titleHlafH = showSelectClickBtn.titleLabel.height * 0.5;

[showSelectClickBtn setTitleEdgeInsets:UIEdgeInsetsMake(imgHlafH,-imgHlafW, -imgHlafH, imgHlafW)];

[showSelectClickBtn setImageEdgeInsets:UIEdgeInsetsMake(-titleHlafH,titleHlafW,titleHlafH, -titleHlafW)];

上一篇下一篇

猜你喜欢

热点阅读