@interface UALabel : UILabel
@property (nonatomic, assign) UIEdgeInsets insets;
@end
@implementation UALabel
#pragma mark - override
- (void)drawTextInRect:(CGRect)rect {
[super drawTextInRect:UIEdgeInsetsInsetRect(rect, self.insets)];
}
- (CGSize)intrinsicContentSize {
CGSize size = [super intrinsicContentSize];
size.width += (self.insets.left + self.insets.right);
size.height += (self.insets.top + self.insets.bottom);
return size;
}
#pragma mark - getter && setter
- (void)setInsets:(UIEdgeInsets)insets {
_insets = insets;
[self layoutSubviews];
}
@end