From c05582af4d79900bbfdeb76c4b54617b9d7e17ed Mon Sep 17 00:00:00 2001 From: Josh Date: Wed, 12 Jun 2013 16:43:15 -0700 Subject: [PATCH] switched from using touchesBegan, touchesEnded to UIControlEventTouchDown, UIControlEventTouchUpInside --- GlossyButtons/GlossyButton.m | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/GlossyButtons/GlossyButton.m b/GlossyButtons/GlossyButton.m index 1b2b739..dfdc78b 100644 --- a/GlossyButtons/GlossyButton.m +++ b/GlossyButtons/GlossyButton.m @@ -9,6 +9,12 @@ #import "GlossyButton.h" #import +@interface GlossyButton() +-(void)wasPressed; +-(void)endedPress; +- (void)makeButtonShiny:(GlossyButton*)button withBackgroundColor:(UIColor*)backgroundColor; +@end + @implementation GlossyButton - (id)initWithFrame:(CGRect)frame withBackgroundColor:(UIColor*)backgroundColor @@ -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; } @@ -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; @@ -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;