自定义UILabel类myLabel
myLabel.h文件中声明一个新的init方法:
- (instancetype)initWithFrame:(CGRect)frame insets:(UIEdgeInsets)insets;
myLabel.m文件中实现drawTextInRect方法:
@implementation myLabel
{
UIEdgeInsets _insets;
}
- (instancetype)initWithFrame:(CGRect)frame insets:(UIEdgeInsets)insets
{
if (self = [superinitWithFrame:frame]) {
_insets = insets;
}
returnself;
}
- (void)drawTextInRect:(CGRect)rect
{
return [superdrawTextInRect:UIEdgeInsetsInsetRect(rect,_insets)];
}