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 7799831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:26:02+00:00 2026-06-02T00:26:02+00:00

I have a simple drawing class. There is a view controller that includes a

  • 0

I have a simple drawing class. There is a view controller that includes a color selection bar. Then a UIView that has the CGRect draw functions.

I can draw ok, but when I change the color, all existing strokes are changed. What have I messed up? I want to only change colors for new strokes.

Any help would be welcome. Here are some relevant code snippets:

- (void)drawRect:(CGRect)rect
{
    [currentColor setStroke]; 

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

#pragma mark - Touch Methods
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    swiped = NO;

    myPath=[[UIBezierPath alloc]init];
    myPath.lineWidth=10;
    UITouch *touch= [touches anyObject];
    [myPath moveToPoint:[touch locationInView:self]];
    [pathArray addObject:myPath];

    if ([touch tapCount] == 2) {
        [self eraseButtonClicked];
        return;
    }

    lastPoint = [touch locationInView:self];
    lastPoint.y -= 20;


}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    swiped = YES;

    UITouch *touch = [touches anyObject];   
    CGPoint currentPoint = [touch locationInView:self];
    currentPoint.y -= 20;

    [myPath addLineToPoint:[touch locationInView:self]];
    [self setNeedsDisplay];

    UIGraphicsBeginImageContext(self.frame.size);
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 15.0);
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), red, green, blue, 1.0);
    CGContextBeginPath(UIGraphicsGetCurrentContext());
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
    CGContextStrokePath(UIGraphicsGetCurrentContext());
    UIGraphicsEndImageContext();

    lastPoint = currentPoint;

    moved++;    
    if (moved == 10) {
        moved = 0;
    }

}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];   
    if ([touch tapCount] == 2) {
        [self eraseButtonClicked];
        return;
    }
}
  • 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-02T00:26:04+00:00Added an answer on June 2, 2026 at 12:26 am

    Your drawRect: is drawing all the paths in the same colour. When you call [currentColor setStroke], you are setting the colour for all the strokes you draw. You’ll need to maintain the colours for the strokes as well, and reset the colour before each call to strokeWithBlendMode.

    Something like:

    - (void)drawRect:(CGRect)rect
    {
        for( int i=0; i<[pathArray count]; i++) {
            [[colorArray objectAtIndex:i] setStroke];
            [[pathArray objectAtIndex:i] strokeWithBlendMode:kCGBlendModeNormal alpha:1.0];
        }
    }
    

    You’ll have to make sure you add a UIColor object to the colorArray every time you add a path to pathArray.

    You could add [colorArray addObject:currentColor]; after the line [pathArray addObject:myPath];

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple class, BoundedView that extends View . I'm doing this primarily
I have a very simple AS3 app that draws few circles using drawing api
I have a class that represents the state of the world. The class has
I have a simple OpenGL drawing. When the user changes the window's size, I
This should be so simple, but I'm drawing a blank. I have two tables.
I have simple win service, that executes few tasks periodically. How should I pass
I have a pretty simple question, but for some reason I am drawing a
I want to XML-Serialize a complex type (class), that has a property of type
I have a simple game that renders 2D graphics to a frame buffer (not
I have a simple square I'm drawing in 3D space using Direct3D 11 and

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.