Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8700111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:06:42+00:00 2026-06-13T02:06:42+00:00

Here is the relevant .m that I am currently using. – (void)drawRect:(CGRect)rect { [[UIColor

  • 0

Here is the relevant .m that I am currently using.

- (void)drawRect:(CGRect)rect
{

    [[UIColor redColor] setStroke];
    for (UIBezierPath *_path in pathArray) 
    [_path strokeWithBlendMode:kCGBlendModeNormal alpha:1.0];    


}

#pragma mark -
#pragma mark - Touch Methods


-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    myPath=[[UIBezierPath alloc]init];


    NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];

    if([ud objectForKey:@"lineThickness"] == nil) {
        myPath.lineWidth=5;
    }
    else {

        float thicknessFloat = [ud floatForKey:@"lineThickness"];
        myPath.lineWidth= 10. * thicknessFloat;


    }

    UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
    [myPath moveToPoint:[mytouch locationInView:self]];
    [pathArray addObject:myPath];

}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{

    UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
    NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];

    if([ud objectForKey:@"lineThickness"] == nil) {
        myPath.lineWidth=5;
    }
    else {

        float thicknessFloat = [ud floatForKey:@"lineThickness"];
        myPath.lineWidth= 10. * thicknessFloat;


    }
    [myPath addLineToPoint:[mytouch locationInView:self]];
    [self setNeedsDisplay];

}

It works great, but since this is tutorial code that is slightly modified by me, I do not know how to approach the problem of wanting to draw lines between two points, and have the framework connect the the points each time a point is added.

Can anyone please point me in a good direction on how to accomplish this please?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:06:43+00:00Added an answer on June 13, 2026 at 2:06 am

    The particulars of how to implement this depend upon the effect that you’re looking for. If you’re just tapping on a bunch of points and want to add them to a UIBezierPath you can do something like the following in your view controller:

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        UITouch *mytouch = [[touches allObjects] objectAtIndex:0];
        CGPoint location = [mytouch locationInView:self.view];
    
        // I'm assuming you have a myPath UIBezierPath which is an ivar which is 
        // initially nil. In that case, we'll check if it's nil and if so, initialize 
        // it, otherwise, it's already been initialized, then we know we're just
        // adding a line segment.
    
        if (!myPath)
        {
            myPath = [UIBezierPath bezierPath];
            [myPath moveToPoint:location];
    
            shapeLayer = [[CAShapeLayer alloc] initWithLayer:self.view.layer];
            shapeLayer.lineWidth = 1.0;
            shapeLayer.strokeColor = [UIColor redColor].CGColor;
            shapeLayer.fillColor = [UIColor clearColor].CGColor;
    
            [self.view.layer addSublayer:shapeLayer];
        }
        else
        {
            [myPath addLineToPoint:location];
            shapeLayer.path = myPath.CGPath;
        }
    }
    

    If you wanted something where you can draw with your finger (e.g. dragging your finger draws), then it might look something like:

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        UITouch *mytouch = [[touches allObjects] objectAtIndex:0];
        CGPoint location = [mytouch locationInView:self.view];
    
        myPath = [UIBezierPath bezierPath];
        [myPath moveToPoint:location];
    
        shapeLayer = [[CAShapeLayer alloc] initWithLayer:self.view.layer];
        shapeLayer.lineWidth = 1.0;
        shapeLayer.strokeColor = [UIColor redColor].CGColor;
        shapeLayer.fillColor = [UIColor clearColor].CGColor;
    
        [self.view.layer addSublayer:shapeLayer];
    }
    
    -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
    {
        UITouch *mytouch = [[touches allObjects] objectAtIndex:0];
        CGPoint location = [mytouch locationInView:self.view];
    
        [myPath addLineToPoint:location];
        shapeLayer.path = myPath.CGPath;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the relevant code: public static void printBoarders (Territory x) { int t =
I'm currently working on a project using C# and SQL Studio 2010 that needs
I have an audio player that I'm building using AVPlayer. Currently, I keep the
We have an application that using the basic JSP/servlet that all text currently in
I am currently using Alexander Potochkin's AspectJ EDTChecker code (relevant code at bottom of
I do not seem to understand how to catch constructor exception. Here is relevant
Here's the relevant code: <div data-bind=foreach: chats, visible: chats().length > 0> <input data-bind='value: $parent.newCommentText'
Here's the relevant code snippet. public static Territory[] assignTerri (Territory[] board, String[] colors) {
Here are the relevant models: User Product Order A User can sell or buy
Here's the relevant bit of the source code: class Dice { String name ;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.