新建一个按钮继承UIButton,只用贴上这段代码就可以用了,button上的图片大小为20x20可以自己改,图片和Label的距离为3.f可改
- (void)layoutSubviews{
[super layoutSubviews];
CGFloat bx = (self.frame.size.width - self.imageView.frame.size.width - self.titleLabel.frame.size.width)/2;
CGRect titleRect = self.titleLabel.frame;
titleRect.origin.x = bx;
titleRect.origin.y = (self.frame.size.height - titleRect.size.height)/2.0f;
CGRect imageRect = self.imageView.frame;
imageRect.size = CGSizeMake(20, 20);
imageRect.origin.x = (bx + self.titleLabel.frame.size.width + 3.f) ;
imageRect.origin.y = (self.frame.size.height - 20)/2.0f;
self.imageView.frame = imageRect;
self.titleLabel.frame = titleRect;
}