@SanMao
2015-08-05T16:33:49.000000Z
字数 846
阅读 1384
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:方法在什么时候被调用?