Skip to content

Instantly share code, notes, and snippets.

@yueqianzhang
Last active May 31, 2018 02:45
Show Gist options
  • Select an option

  • Save yueqianzhang/013bfd2bfd00fae9ff297c2e676effaa to your computer and use it in GitHub Desktop.

Select an option

Save yueqianzhang/013bfd2bfd00fae9ff297c2e676effaa to your computer and use it in GitHub Desktop.
设置按钮文字图片垂直显示的分类
#import "UIButton+VerticalLayout.h"
@implementation UIButton (VerticalLayout)
- (void)setVerticalLayoutWithSpace:(CGFloat)itemSpace
{
CGFloat spacing = itemSpace;
CGSize imageSize = self.imageView.image.size;
self.titleEdgeInsets = UIEdgeInsetsMake(0.0, -imageSize.width, -(imageSize.height + spacing), 0.0);
CGSize titleSize = [self.titleLabel.text sizeWithAttributes:@{NSFontAttributeName : self.titleLabel.font}];
self.imageEdgeInsets = UIEdgeInsetsMake(-(titleSize.height + spacing), 0.0, 0.0, -titleSize.width);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment