Mega-Gold Challenge


Nothing about this challenge has been covered in the book so far besides the gesture stuff. Am I seriously missing something? I have no idea where to begin on this…


Not sure if I’m going to try this challenge as (I think) there is no way of implementing the 3 fingered swipe on the iOS simulator.
Maybe this will help though:


@Monkeyboy: why not just use a two-finger swipe? the challenge remains the same


I completed this using the simulator and opted for a new UIViewController subclass that displays a number of buttons, each with a different background colour. I used UIViewController’s presentViewController:animated:completion: and hooked up all the communication between the UIViewControllers and the BNRDrawView.

@jwgraz: Thanks for the suggestion.


Hey guys,

I’ve got it working. First of all you need to handle the gesture. In initWithFrame add:

UISwipeGestureRecognizer *threeFingerSwipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(displayPanel:)];
[threeFingerSwipe setDirection:UISwipeGestureRecognizerDirectionUp];
[threeFingerSwipe setNumberOfTouchesRequired:3];
[threeFingerSwipe setDelaysTouchesBegan:YES];
[self addGestureRecognizer:threeFingerSwipe];

Next you need to create a *.xib file. Call it “ColorSelectView”. Mine looks like that:

It’s just five buttons with no text, different backgroundColor. Set the File’s owner to BNRDrawView, create a property

and connect it to the View in *.xib

Now we need to add the view after the swipe gesture, implement the displayPanel method:

-(void)displayPanel:(UIGestureRecognizer *)gr { NSLog(@"swiped up"); CGRect frame = CGRectMake(0, self.window.frame.size.height-50, self.window.frame.size.width, 50); NSLog(@"%@",NSStringFromCGRect(frame)); [[NSBundle mainBundle] loadNibNamed:@"ColorSelectView" owner:self options:nil]; UIView *colorSelect = self.colorView; self.colorView.frame = frame; [self.window addSubview:colorSelect]; [self.window setNeedsDisplay]; }

Now you should add the

to BNRDrawView.m

Next we need to implement the color, so open BNRLine.h and add a property:

No we need the ViewController to draw the lines of selected color, first set up the default color in initWithFrame:

Next modify the touchesEnded method where we create the BNRLine object:

[code]-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
for(UITouch *t in touches){
NSValue *key = [NSValue valueWithNonretainedObject:t];
BNRLine *line = self.linesInProgress[key];
line.color = self.selectedColor;
[self.finishedLines addObject:line];
[self.linesInProgress removeObjectForKey:key];

[self setNeedsDisplay];


We need to modify the drawRect method, so it draws back finishedLines with their respective colors:

// [self.selectedColor set];
for (BNRLine *line in self.finishedLines)
[line.color set];
[self strokeLine:line];

    [[UIColor greenColor] set];
    [self strokeLine:self.selectedLine];

[[UIColor redColor] set];
for(NSValue *key in self.linesInProgress){
    [self strokeLine:self.linesInProgress[key]];


Now connect all the buttons from the *.xib to ONE method:

[code]- (IBAction)colorSelected:(UIButton *)sender {
self.selectedColor = sender.backgroundColor;
[self.colorView removeFromSuperview];


This sets the selectedColor and dismisses the view. And voila, you’re set.


Hey gh0st87,

I was going to do exactly the same thing that you did. But I just cannot make an outlet from the new view with the xib to the DrawView.

this part just doesnt work for me… =(

can you please explain how exactly did you make a connection?