美文网首页
UILabel 如何加padding

UILabel 如何加padding

作者: zimo | 来源:发表于2015-04-03 09:34 被阅读4459次

#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

      本文链接:https://www.haomeiwen.com/subject/zbtaxttx.html