-
Notifications
You must be signed in to change notification settings - Fork 0
/
PaddingLabel.m
40 lines (32 loc) · 906 Bytes
/
PaddingLabel.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
//
// UIPaddingLabel.m
//
// Created by openapphub on 2024/10/18.
//
// PaddingLabel.m
#import "PaddingLabel.h"
@implementation PaddingLabel
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
_textInsets = UIEdgeInsetsZero;
}
return self;
}
- (void)drawTextInRect:(CGRect)rect {
[super drawTextInRect:UIEdgeInsetsInsetRect(rect, self.textInsets)];
}
- (CGSize)intrinsicContentSize {
CGSize size = [super intrinsicContentSize];
size.width += self.textInsets.left + self.textInsets.right;
size.height += self.textInsets.top + self.textInsets.bottom;
return size;
}
- (void)sizeToFit {
[super sizeToFit];
CGRect frame = self.frame;
frame.size.width += self.textInsets.left + self.textInsets.right;
frame.size.height += self.textInsets.top + self.textInsets.bottom;
self.frame = frame;
}
@end