Skip to content
Browse files

Implement setHighlighted in CBBezier

  • Loading branch information...
1 parent 2ef2968 commit 473251dde2af1d2867b5c4d350619aaf9772d450 @kaishin committed
Showing with 5 additions and 40 deletions.
  1. +0 −2 Custom UIButtons/CBBezier.h
  2. +5 −38 Custom UIButtons/CBBezier.m
View
2 Custom UIButtons/CBBezier.h
@@ -3,6 +3,4 @@
@interface CBBezier : UIButton
-@property (assign,nonatomic) BOOL tapped;
-
@end
View
43 Custom UIButtons/CBBezier.m
@@ -9,47 +9,14 @@ + (CBBezier *)buttonWithType:(UIButtonType)type
return [super buttonWithType:UIButtonTypeCustom];
}
-#pragma mark - Touch event overrides
-
--(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
-{
- _tapped = YES;
- [self setNeedsDisplay];
- [super touchesBegan:touches withEvent:event];
-}
-
--(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
+- (void)setHighlighted:(BOOL)highlighted
{
- _tapped = NO;
- [self setNeedsDisplay];
- [super touchesEnded:touches withEvent:event];
+ [self setNeedsDisplay];
+ [super setHighlighted:highlighted];
}
-// The distance from the button beyond which the former should no longer be considered tapped
-static CGFloat touchDistance = 70;
+#pragma mark - Touch event overrides
--(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
-{
- // Get the distance between the touch point and the button bounds
- CGPoint touchPoint = [[touches anyObject] locationInView:self];
-
- // Define the touch area frame using the touch distance defined above
- CGRect touchArea = CGRectMake(0, - touchDistance, CGRectGetWidth(self.frame), CGRectGetHeight(self.frame) + touchDistance * 2);
-
- if (CGRectContainsPoint(touchArea, touchPoint))
- {
- _tapped = YES;
- [self setNeedsDisplay];
- }
-
- else
- {
- _tapped = NO;
- [self setNeedsDisplay];
- }
-
- [super touchesMoved:touches withEvent:event];
-}
- (void)drawRect:(CGRect)rect
{
@@ -85,7 +52,7 @@ - (void)drawRect:(CGRect)rect
[roundedRectanglePath addClip];
// Use one of the two gradients depending on the state of the button
- CGGradientRef background = _tapped? highlightedGradient : gradient;
+ CGGradientRef background = self.highlighted? highlightedGradient : gradient;
// Draw gradient within the path
CGContextDrawLinearGradient(context, background, CGPointMake(140, 0), CGPointMake(140, 37), 0);

0 comments on commit 473251d

Please sign in to comment.
Something went wrong with that request. Please try again.