继承UIButton类创建
在.m中添加方法
- (void)layoutButtonWithImageTitleSpace:(CGFloat)space {
CGFloat imageWith = self.imageView.image.size.width;
CGFloat imageHeight = self.imageView.image.size.height;
CGFloat labelWidth = self.titleLabel.intrinsicContentSize.width;
CGFloat labelHeight = self.titleLabel.intrinsicContentSize.height;
UIEdgeInsets imageEdgeInsets = UIEdgeInsetsMake(-labelHeight-space/2.0, 0, 0, -labelWidth);
UIEdgeInsets labelEdgeInsets = UIEdgeInsetsMake(0, -imageWith, -imageHeight-space/2.0, 0);
self.titleEdgeInsets = labelEdgeInsets;
self.imageEdgeInsets = imageEdgeInsets;
}
在需要的时候调用后,Button会改为上下布局
网友评论