//文字在左,图片在右
CGFloat imageWidth = self.button.imageView.frame.size.width;
CGFloat labelWidth = self.button.titleLabel.frame.size.width;
self.button.imageEdgeInsets = UIEdgeInsetsMake(0, labelWidth, 0, -labelWidth);
self.button.titleEdgeInsets = UIEdgeInsetsMake(0, -imageWidth, 0, imageWidth);
//图片在上,文字在下
CGFloat imageHeight = self.button.imageView.frame.size.height;
CGFloat imageWidth = self.button.imageView.frame.size.width;
CGFloat labelWidth = self.button.titleLabel.frame.size.width;
[self.button setTitleEdgeInsets:UIEdgeInsetsMake(imageHeight+ 20 ,-imageWidth , 0.0,0.0)];//文字距离上边框的距离增加imageView的高度,距离左边框减少imageView的宽度,距离下边框和右边框距离不变
[self.button setImageEdgeInsets:UIEdgeInsetsMake(0.0, 0.0,0.0, -labelWidth)];//图片距离右边框距离减少图片的宽度,其它不边
时间: 2024-10-11 01:32:12