设置button式样为上图片下文字(最好不要用约束布局,先设置button的frame、image和title) 若发现有不符合预期的情况,适当更改button的size
CGFloat spacing = 10;
CGSize imgVSize = btn.imageView.frame.size;
CGSize labelSize = btn.titleLabel.frame.size;
CGFloat totalHeight = (imgVSize.height + labelSize.height + spacing);
btn.imageEdgeInsets = UIEdgeInsetsMake(- (totalHeight - imgVSize.height), 0.0, 0.0, - labelSize.width);
btn.titleEdgeInsets = UIEdgeInsetsMake(0, - imgVSize.width, - (totalHeight - labelSize.height), 0);
设置左文字右图片
[btn setTitleEdgeInsets:UIEdgeInsetsMake(0, - imgVSize.width, 0, imgVSize.width)];
[btn setImageEdgeInsets:UIEdgeInsetsMake(0, labelSize.width, 0, -labelSize.width)];