// Created by guoya song on 16/8/10.
// Copyright © 2016年 guoyasong. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@interface TestUILabel : UILabel
@end
@implementation TestUILabel
- (void)drawTextInRect:(CGRect)rect {
//文字距离上下左右边框都有10单位的间隔
CGRect newRect = CGRectMake(rect.origin.x + 10, rect.origin.y + 10, rect.size.width - 20, rect.size.height -20);
[super drawTextInRect:newRect];
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UILabel *myLabel=[[TestUILabel alloc]initWithFrame:CGRectMake(100,100, 100, 20)];
myLabel.text=@"我的三";
myLabel.layer.borderWidth=1;
[myLabel drawTextInRect:myLabel.frame];
[self.view addSubview:myLabel];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
网友评论