使用最简单的方法在UIView上绘图的分类
导入
#import "UIView+DrawBlock.h"
使用它!返回一个包含绘图的UIView的block。
[viewToDraw drawInside:^(CGContextRef context, CGRect rect) {
// Draw
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
CGContextSetLineWidth(context, 5.0);
CGContextBeginPath(context);
CGContextMoveToPoint(context, 0.0, 0.0);
CGContextAddLineToPoint(context, 100.0, 100.0);
CGContextStrokePath(context);
} withResult:^(UIView *view) {
// Do what you want!
}];
需要Xcode 5,目标为iOS 6.0或更高版本