/**
* 画文字
*/
- (void)drawRect:(CGRect)rect {
//1.获得图形上下文
CGContextRef ctx = UIGraphicsGetCurrentContext();
//2.画文字
NSString *str = @"哈哈哈哈";
[str drawAtPoint:CGPointZero withAttributes:nil];
//文字属性字典
NSMutableDictionary *atts = [NSMutableDictionary dictionary];
atts[NSForegroundColorAttributeName] = [UIColor redColor];
atts[NSFontAttributeName] = [UIFont systemFontOfSize:20];
[str drawInRect:CGRectMake(50, 50, 100, 100) withAttributes:atts];
//3.渲染显示到view上
CGContextStrokePath(ctx);
}
/**
* 画图片
*/
- (void)drawRect:(CGRect)rect {
//1.取得图片
UIImage *image = [UIImage imageNamed:@"me"];
//2.画
[image drawAtPoint:CGPointMake(50, 50)];
[image drawInRect:CGRectMake(0, 0, 150, 150)];
[image drawAsPatternInRect:CGRectMake(0, 0, 200, 200)]; //平铺图片
}