DrawRect
来源:互联网 发布:域名的价格top 编辑:程序博客网 时间:2024/06/04 20:11
在RootView.m里重写如下方法
- (void)drawRect:(CGRect)rect{ // 初始化一个路线// self.path = [UIBezierPath bezierPath]; // 点之间的过度效果// _path.lineCapStyle = kCGLineCapRound; // 设置节点过度效果// _path.lineJoinStyle = kCGLineJoinRound; // 设置终点过度效果// _path.lineWidth = 3.0; // 设置线宽// // [_path moveToPoint:CGPointMake(100, 100)];// // [_path addLineToPoint:CGPointMake(150, 150)];// [path addLineToPoint:CGPointMake(180, 130)];// [path addLineToPoint:CGPointMake(200, 170)];// [path addLineToPoint:CGPointMake(120, 180)];// // [path stroke]; // 得到上下文 1 在drawRect拿到上下文 2 通过一个image图片拿到上下文// CGContextRef context = UIGraphicsGetCurrentContext();// // 设置了画笔的颜色// CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);// // 设置画笔的粗细// CGContextSetLineWidth(context, 2.0); for (UIBezierPath *path in self.paths) { [path stroke]; }}- (NSMutableArray *)paths{ if (!_paths) { _paths = [NSMutableArray array]; } return _paths;}- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ // 获取touch对象 UITouch *touch = [touches anyObject]; // 获取touch起始点 CGPoint point = [touch locationInView:touch.view]; // 创建路径对象 UIBezierPath *path = [UIBezierPath bezierPath]; path.lineWidth = 3.0; path.lineCapStyle = kCGLineCapRound; path.lineJoinStyle = kCGLineJoinRound; // 设置起点 [path moveToPoint:point]; // 添加路径 [self.paths addObject:path];}- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ // 获取touch对象 UITouch *touch = [touches anyObject]; CGPoint point = [touch locationInView:touch.view]; UIBezierPath *path = [self.paths lastObject]; [path addLineToPoint:point]; [self setNeedsDisplay];}- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ [self touchesMoved:touches withEvent:event];}
0 0
- drawRect()
- drawRect
- drawRect
- DrawRect
- DrawRect
- drawrect
- DrawRect
- drawRect introduce
- drawRect绘图
- drawRect方法
- ios drawRect
- layoutSubviews & drawRect
- Cocoa drawRect
- DrawRect 图形
- drawRect方法
- 绘图drawrect
- drawRect 进阶
- drawRect方法
- CoreData
- oracle学习笔记-1
- BZOJ 3294: [Cqoi2011]放棋子
- 第78题 Binary Tree Level Order Traversal
- <C#> var--隐式类型
- DrawRect
- 菜鸟学设计模式系列笔记之Prototype模式(原型模式)
- 初级驱动模板之实现【驱动模板信息】
- 2015-第9周项目1-复数类中的运算符重载(续)
- Relativelayout(相对布局)示例
- 用户及文件权限管理
- 黑马程序员:iOS基础——个人笔记(十)
- hdu 1217 Arbitrage
- Markdown语法及SublimeText下使用技巧