UIButton居中图片和文字
- (void)centerImageAndButton:(CGFloat)gap imageOnTop:(BOOL)imageOnTop { NSInteger sign = imageOnTop ? 1 : -1; CGSize imageSize = self.imageView.frame.size; self.titleEdgeInsets = UIEdgeInsetsMake((imageSize.height+gap)*sign, -imageSize.width, 0, 0); CGSize titleSize = self.titleLabel.bounds.size; self.imageEdgeInsets = UIEdgeInsetsMake(-(titleSize.height+gap)*sign, 0, 0, -titleSize.width); }
原文 http://koofrank.com/2014/03/08/ios-tool2/