创建UILabel的子类使其能够让文字有上下左右的空隙

@interface SubLabel : UILabel

 

@property (nonatomic, assign) UIEdgeInsets insets;

 

@end

- (id)initWithFrame:(CGRect)frame

{

    self = [super initWithFrame:frame];

    if (self) {

        self.insets = UIEdgeInsetsMake(0.0f, 0.0f, 0.0f, 0.0f);

    }

    returnself;

}

 

- (void)drawTextInRect:(CGRect)rect

{

    UIEdgeInsets insets = _insets;

    

    [superdrawTextInRect:UIEdgeInsetsInsetRect(rect, insets)];

}

猜你喜欢

转载自zhangmingwei.iteye.com/blog/2043114