@SanMao
2015-08-06T00:33:49.000000Z
字数 846
阅读 1268
UI
CGContextRef
类型的数据在自定义View中重写drawRect:
方法
- (void)drawRect:(CGRect)rect {
// 获取上下文
CGContextRef ctx = UIGraphicsGetCurrentContext();
// 拼接路径
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(10, 150)];
[path addLineToPoint:CGPointMake(290, 150)];
[path moveToPoint:CGPointMake(150, 10)];
[path addLineToPoint:CGPointMake(150, 290)];
// 将路径添加到上下文
CGContextAddPath(ctx, path.CGPath);
// 渲染上下文
CGContextStrokePath(ctx);
}
为什么要实现drawRect:方法才能绘图到view上?
drawRect:方法在什么时候被调用?