1234567891011121314151617181920212223242526272829303132333435363738 |
- //
- // UIButton+Layout.m
- // LenzCameraNativeModuleForRN
- //
- // Created by 王昭威 on 2023/1/23.
- //
- #import "UIButton+Layout.h"
- @implementation UIButton (Layout)
- - (void)centerVerticallyWithPadding:(float)padding {
- CGSize imageSize = self.imageView.frame.size;
- CGSize titleSize = self.titleLabel.frame.size;
- CGFloat totalHeight = (imageSize.height + titleSize.height + padding);
-
- self.imageEdgeInsets = UIEdgeInsetsMake(- (totalHeight - imageSize.height),
- 0.0f,
- 0.0f,
- - titleSize.width);
-
- self.titleEdgeInsets = UIEdgeInsetsMake(0.0f,
- - imageSize.width,
- - (totalHeight - titleSize.height),
- 0.0f);
-
- self.contentEdgeInsets = UIEdgeInsetsMake(0.0f,
- 0.0f,
- titleSize.height,
- 0.0f);
- }
- - (void)centerVertically {
- const CGFloat kDefaultPadding = 6.0f;
- [self centerVerticallyWithPadding:kDefaultPadding];
- }
- @end
|