欢迎来到天天文库
浏览记录
ID:8809702
大小:1.51 MB
页数:7页
时间:2018-04-08
《ios应用开发——小画板demo》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、iOS应用开发——小画板Demo代码部分TouchView.h1#import 2 3@interface TouchView : UIView 4{ 5 NSMutableArray *points; 6 NSArray *points_all; 7 CGContextRef context; 8 UIColor *paint_clr; 9} 10@property (strong,nonatomic) NSMutableArray *poin
2、ts; 11@property (strong,nonatomic) NSArray *points_all; 12@property (strong,nonatomic) UIColor *paint_clr; 13 14@end TouchView.m1#import "TouchView.h" 2 3@implementation TouchView 4@synthesize points, points_all, paint_clr; 5 6- (id)initWithFrame:(CGRe
3、ct)frame 7{ 8 self = [super initWithFrame:frame]; 9 if (self) { 10 // Initialization code 11 paint_clr = [UIColor greenColor]; 12 } 13 return self; 14} 15 16// Only override drawRect: if you perform custom drawing. 17// An em
4、pty implementation adversely affects performance during animation. 18- (void)drawRect:(CGRect)rect 19{ 20 // Drawing code 21 if ((!self.points)
5、
6、 (self.points.count < 2)) { 22 return; 23 } 24 25 context = UIGraphicsGetCurrentCon
7、text(); 26 //设置画笔粗细 27 CGContextSetLineWidth(context, 5.0f); 28 //设置画笔颜色 29 //[[UIColor blueColor]set ]; 30 // [paint_clr set]; 31 //CGContextSetStrokeColorWithColor(context, [[UIColor blueColor]CGColor]); 32 CGContextSetStrokeColorW
8、ithColor(context, [paint_clr CGColor]); 33 34 //画以前的轨迹 35 for (int j = 0 ; j < [self.points_all count]; j++) { 36 NSMutableArray *points_tmp = [points_all objectAtIndex:j]; 37 38 for (int i = 0;i < [points_tmp count]
9、-1;i++) 39 { 40 CGPoint point1 = [[points_tmp objectAtIndex:i] CGPointValue]; 41 CGPoint point2 = [[points_tmp objectAtIndex:(i+1)] CGPointValue]; 42 CGContextMoveToPoint(context, point1.x, point1.y);
10、43 CGContextAddLineToPoint(context, point2.x, point2.y); 44 CGContextStrokePath(context); 45 } 46 } 47 48
此文档下载收益归作者所有