Skip to content

Commit

Permalink
switched from using touchesBegan, touchesEnded to UIControlEventTouch…
Browse files Browse the repository at this point in the history
…Down, UIControlEventTouchUpInside
  • Loading branch information
Jpro714 committed Jun 12, 2013
1 parent 992772a commit c05582a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions GlossyButtons/GlossyButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
#import "GlossyButton.h"
#import <QuartzCore/QuartzCore.h>

@interface GlossyButton()
-(void)wasPressed;
-(void)endedPress;
- (void)makeButtonShiny:(GlossyButton*)button withBackgroundColor:(UIColor*)backgroundColor;
@end

@implementation GlossyButton

- (id)initWithFrame:(CGRect)frame withBackgroundColor:(UIColor*)backgroundColor
Expand All @@ -19,6 +25,9 @@ - (id)initWithFrame:(CGRect)frame withBackgroundColor:(UIColor*)backgroundColor
//save our color so we can alter it upon a touch event
self.myColor = backgroundColor;
[self makeButtonShiny:self withBackgroundColor:backgroundColor];
[self addTarget:self action:@selector(wasPressed) forControlEvents:UIControlEventTouchDown];
[self addTarget:self action:@selector(endedPress) forControlEvents:UIControlEventTouchUpInside];

}
return self;
}
Expand Down Expand Up @@ -60,7 +69,7 @@ - (void)makeButtonShiny:(GlossyButton*)button withBackgroundColor:(UIColor*)back

//When button is touched, grab our existing color and make it 20% darker (or lighter if its black)
//We will return it to its original state when the touch is lifted and touchesEnded:withEvent: is called
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
-(void)wasPressed
{
UIColor *newColor;
CGFloat red = 0.0, green = 0.0, blue = 0.0, alpha = 0.0, white = 0.0;
Expand Down Expand Up @@ -104,7 +113,7 @@ -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
-(void)endedPress
{
//Reset our button to its original color
self.backgroundColor = self.myColor;
Expand Down

0 comments on commit c05582a

Please sign in to comment.