我正在尝试绘制一个显示在 imageview 上的随机图形,我尝试使用此代码
-(void)createGraph{
UIGraphicsBeginImageContext(self.drawImage.frame.size);
[drawImage.image drawInRect:CGRectMake(0, 0, drawImage.frame.size.width, drawImage.frame.size.height)];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
CGContextSetLineWidth(context, 2.0);
int i = 0;
while (i<=20) {
int r = rand() % 100;
CGContextMoveToPoint(context, 20, 320);
CGContextAddLineToPoint(context, linePoint.x+20+i*r, linePoint.y+320-i*r);
CGContextStrokePath(context);
i++;
NSLog(@"random value %d",r);
}
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
}
但它在单线上画了一条对角线。已显示在下图中
我期待画一条曲线!使用核心图形