UILabel 如何加padding

#import@interface PaddingLabel : UILabel

@property (nonatomic, assign) UIEdgeInsets edgeInsets;

@end

#import "PaddingLabel.h"

@implementation PaddingLabel

@synthesize edgeInsets;

- (id)initWithFrame:(CGRect)frame

{

self = [super initWithFrame:frame];

if (self) {

self.edgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);

}

return self;

}

- (void)drawRect:(CGRect)rect

{

[super drawTextInRect:UIEdgeInsetsInsetRect(rect, self.edgeInsets)];

}

- (CGSize)intrinsicContentSize

{

CGSize size = [super intrinsicContentSize];

size.width  += self.edgeInsets.left + self.edgeInsets.right;

size.height += self.edgeInsets.top + self.edgeInsets.bottom;

return size;

}

你可能感兴趣的:(UILabel 如何加padding)