Skip to content

Commit

Permalink
Merge pull request #2 from Jpro714/touch-effect
Browse files Browse the repository at this point in the history
switched from using touchesBegan to UIControlEventTouchDown
  • Loading branch information
ijason committed Jun 13, 2013
2 parents 04be1e2 + c05582a commit db97cc9
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 db97cc9

Please sign in to comment.