-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathYLEdgeLabel.m
73 lines (62 loc) · 1.73 KB
/
YLEdgeLabel.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
// YLEdgeLabel.m
// https://www.jianshu.com/u/d2c069de1a7d
//
// Created by yanglin on 2018/4/25.
// Copyright © 2018年 yanglin. All rights reserved.
//
#import "YLEdgeLabel.h"
@implementation YLEdgeLabel
@synthesize contentEdgeInsets = _contentEdgeInsets;
- (void)setContentEdgeInsets:(UIEdgeInsets)contentEdgeInsets
{
_contentEdgeInsets = contentEdgeInsets;
_topEdge = _contentEdgeInsets.top;
_leftEdge = _contentEdgeInsets.left;
_rightEdge = _contentEdgeInsets.right;
_bottomEdge = _contentEdgeInsets.bottom;
[self invalidateIntrinsicContentSize];
}
- (void)setTopEdge:(CGFloat)topEdge
{
_topEdge = topEdge;
[self invalidateIntrinsicContentSize];
}
- (void)setLeftEdge:(CGFloat)leftEdge
{
_leftEdge = leftEdge;
[self invalidateIntrinsicContentSize];
}
- (void)setBottomEdge:(CGFloat)bottomEdge
{
_bottomEdge = bottomEdge;
[self invalidateIntrinsicContentSize];
}
- (void)setRightEdge:(CGFloat)rightEdge
{
_rightEdge = rightEdge;
[self invalidateIntrinsicContentSize];
}
- (UIEdgeInsets)contentEdgeInsets
{
_contentEdgeInsets = UIEdgeInsetsMake(_topEdge, _leftEdge, _bottomEdge, _rightEdge);
return _contentEdgeInsets;
}
- (CGSize)intrinsicContentSize
{
CGSize size = [super intrinsicContentSize];
size.height += (_topEdge + _bottomEdge);
size.width += (_leftEdge + _rightEdge);
return size;
}
- (CGSize)sizeThatFits:(CGSize)size
{
CGSize newSize = [super sizeThatFits:size];
newSize.height += (_topEdge + _bottomEdge);
newSize.width += (_leftEdge + _rightEdge);
return newSize;
}
-(void)drawTextInRect:(CGRect)rect {
[super drawTextInRect:UIEdgeInsetsInsetRect(rect, UIEdgeInsetsMake(_topEdge, _leftEdge, _bottomEdge, _rightEdge))];
}
@end