Drawing a bezier curve between a set of given points

后端 未结 6 1728
春和景丽
春和景丽 2021-02-13 13:40

What is the best way to draw a bezier curve, in iOS application, that passes through a set of given points

6条回答
  •  萌比男神i
    2021-02-13 14:11

    Please try this.

    UIImageView *waterLevel = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,200,200)];
    UIGraphicsBeginImageContext(waterLevel.frame.size);
    [waterLevel.image drawAtPoint:CGPointZero];
    //define BezierPath
    UIBezierPath *bezierPath = [UIBezierPath bezierPath];
    
    
    // Set the starting point of the shape.
    [bezierPath moveToPoint:CGPointMake(0, 0)];
    
    [bezierPath addLineToPoint:CGPointMake(waterLevel.frame.size.width, 0)];
    [bezierPath addLineToPoint:CGPointMake(waterLevel.frame.size.width, waterLevel.frame.size.height)];
    [bezierPath addLineToPoint:CGPointMake(0, waterLevel.frame.size.height)];
    [bezierPath closePath];
    
    bezierPath.lineWidth = 15;
    //set the stoke color
    [[UIColor blackColor] setStroke];
    //draw the path
    [bezierPath stroke];
    
    // Add to the current Graphic context
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextAddPath(context,bezierPath.CGPath);
    waterLevel.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    [self.view addSubview:waterLevel];
    

提交回复
热议问题