Search code examples
iosobjective-ccalayeruibezierpath

How to change a Shape of UIBezierPath Drawing line?


Is there any way to change the UIBezierPath drawing shape ,see the below image it like a line when user drag the finger,but i want star ,circle and other is there any way to achieve that.

enter image description here

My Expectation is enter image description here

This is my UIBezierPath code:

-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
    {
        UITouch *touch = [[event allTouches] anyObject];
        touchPoint = [touch locationInView:self];

        if (!CGPointEqualToPoint(startingPoint, CGPointZero))
        {
            UIBezierPath *path = [UIBezierPath bezierPath];
            [path moveToPoint:CGPointMake(touchPoint.x,touchPoint.y)];
            [path addLineToPoint:CGPointMake(startingPoint.x,startingPoint.y)];

            CAShapeLayer *shapeLayer = [CAShapeLayer layer];
            shapeLayer.path = [path CGPath];
            shapeLayer.strokeColor = [single.arrColor[single.i] CGColor];
            if([UIDevice currentDevice].userInterfaceIdiom ==UIUserInterfaceIdiomPad)
            {
                shapeLayer.lineWidth = 7.0;

            }
            else
            {
                shapeLayer.lineWidth = 5.0;

            }
            shapeLayer.fillColor = [[UIColor redColor] CGColor];
            [self.layer addSublayer:shapeLayer];
            [clearBeizer addObject:shapeLayer];
        }
        startingPoint=touchPoint;
        //    [arrLayer addObject:shapeLayer];
        NSLog(@"Touch moving point =x : %f Touch moving point =y : %f", touchPoint.x, touchPoint.y);
    }

Solution

  • I am simply done this using UIImageView :

     UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:single.arrimages[single.colorimages]]];
                    imageView.frame = CGRectMake(touchPoint.x, touchPoint.y, 30,30);
                    [self addSubview:imageView];
    

    just add image while user touch the screen.

    get the x , y coordination of user touch and give it to uiimageview frame.

    i Hope it will help for some one.