-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUIButton+VerticalLayout.m
executable file
·42 lines (30 loc) · 1.22 KB
/
UIButton+VerticalLayout.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//
// UIButton+VerticalLayout.m
// FTB
//
// Created by 邵小东 on 15/1/5.
// Copyright (c) 2015年 Ugood Technology, LLC. All rights reserved.
//
#import "UIButton+VerticalLayout.h"
@implementation UIButton (VerticalLayout)
- (void)centerVerticallyWithPadding:(float)padding
{
CGSize imageSize = self.imageView.frame.size;
// CGSize titleSize = self.titleLabel.frame.size;
CGSize titleSize = [self.titleLabel.text sizeWithAttributes: @{NSFontAttributeName:self.titleLabel.font}];
CGFloat totalHeight = (imageSize.height + titleSize.height + padding);
self.imageEdgeInsets = UIEdgeInsetsMake(- (totalHeight - imageSize.height-padding),
0.0f,
0.0f,
- titleSize.width);
self.titleEdgeInsets = UIEdgeInsetsMake(0.0f,
- imageSize.width,
- (totalHeight - titleSize.height-padding),
0.0f);
}
- (void)centerVertically
{
const CGFloat kDefaultPadding = 2.0f;
[self centerVerticallyWithPadding:kDefaultPadding];
}
@end