Last active
May 31, 2018 02:45
-
-
Save yueqianzhang/013bfd2bfd00fae9ff297c2e676effaa to your computer and use it in GitHub Desktop.
设置按钮文字图片垂直显示的分类
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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