Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Override UIButton +buttonWithType

  • Loading branch information...
commit ce7287fe5bde0b11dc0f75ef63db06f6f0d58387 1 parent e77c2a2
@kaishin authored
Showing with 15 additions and 8 deletions.
  1. +14 −8 Custom UIButtons/CBLayer.m
  2. +1 −0  Custom UIButtons/CBViewController.m
View
22 Custom UIButtons/CBLayer.m
@@ -10,6 +10,13 @@ @interface CBLayer ()
@implementation CBLayer
+#pragma mark - UIButton Overrides
+
++ (CBLayer *)buttonWithType:(UIButtonType)type
+{
+ return [super buttonWithType:UIButtonTypeCustom];
+}
+
#pragma mark -
- (void)drawRect:(CGRect)rect
@@ -21,9 +28,9 @@ - (void)drawRect:(CGRect)rect
self.layer.borderWidth = 1;
self.layer.borderColor = [UIColor colorWithRed:0.77f green:0.43f blue:0.00f alpha:1.00f].CGColor;
- [self setInnerGlow];
- [self setBackgroundLayer];
- [self setHighlightBackgroundLayer];
+ [self drawInnerGlow];
+ [self drawBackgroundLayer];
+ [self drawHighlightBackgroundLayer];
}
@@ -42,7 +49,7 @@ - (void)drawRect:(CGRect)rect
#pragma mark - Layer setters
-- (void)setBackgroundLayer
+- (void)drawBackgroundLayer
{
if (!_backgroundLayer)
{
@@ -61,7 +68,7 @@ - (void)setBackgroundLayer
}
}
-- (void)setHighlightBackgroundLayer
+- (void)drawHighlightBackgroundLayer
{
if (!_highlightBackgroundLayer)
{
@@ -79,7 +86,7 @@ - (void)setHighlightBackgroundLayer
}
}
-- (void)setInnerGlow
+- (void)drawInnerGlow
{
if (!_innerGlow)
{
@@ -114,9 +121,8 @@ -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint touchPoint = [[touches anyObject] locationInView:self];
- CGRect testRect = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
- if (CGRectContainsPoint(testRect, touchPoint))
+ if (CGRectContainsPoint(self.bounds, touchPoint))
{
_tapped = YES;
[self setNeedsDisplay];
View
1  Custom UIButtons/CBViewController.m
@@ -1,4 +1,5 @@
#import "CBViewController.h"
+#import "CBLayer.h"
@interface CBViewController ()
Please sign in to comment.
Something went wrong with that request. Please try again.