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)];
网友评论