mardi 4 août 2015

How to fill draw a line on UIBezierPath using UIBezierPath

I am working on shapes app.My app is like this. I have different shapes(Triangle,square,circle..) with lines. (See attached image).

I have to fill out lines my drawing.

Sample Image

I draw a image by using

   UIBezierPath* aShape;
    aShape = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0,0,rect.size.width,rect.size.height) cornerRadius:1.0];
    [[UIColor whiteColor] setStroke];
    [[UIColor blueColor] setFill]; 
    aShape.lineWidth = 30;
    [aShape fill];
    [aShape stroke];

So the result is

Result Image

I added the code to draw a line as

 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint p = [touch locationInView:self];
    [path moveToPoint:p];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
     UITouch *touch = [touches anyObject];
    CGPoint p = [touch locationInView:self];

    UIBezierPath *tempPath = [self tapTargetForPath:aShape];
    [path addLineToPoint:p]; // (4)
    [self setNeedsDisplay];

}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
   {
      [self touchesMoved:touches withEvent:event];
  }

Give any trick to achieve this. The result should be like this. Result Image

Aucun commentaire:

Enregistrer un commentaire