Permalink
Browse files

Remove unused layer masking

- Fix formatting
- Add blog post link
  • Loading branch information...
1 parent c69dbad commit 39d4ec28899c24e7fcc9cc03e7efd0944d3fed15 Reda Lemeden committed Oct 14, 2012
Showing with 19 additions and 30 deletions.
  1. +18 −19 Custom UIButtons/CBLayer.m
  2. +1 −11 README.md
@@ -17,34 +17,36 @@ + (CBLayer *)buttonWithType:(UIButtonType)type
return [super buttonWithType:UIButtonTypeCustom];
}
-- (id) initWithCoder:(NSCoder *)coder {
+- (id)initWithCoder:(NSCoder *)coder
+{
self = [super initWithCoder:coder];
- if (self) {
+
+ if (self)
+ {
[self drawButton];
[self drawInnerGlow];
[self drawBackgroundLayer];
[self drawHighlightBackgroundLayer];
_highlightBackgroundLayer.hidden = YES;
}
+
return self;
}
-- (void) layoutSubviews
+- (void)layoutSubviews
{
- // Set the frame (1pt inset)
- CGRect innerGlowFrame = CGRectInset(self.bounds, 1, 1);
- _innerGlow.frame = innerGlowFrame;
-
+ // Set layer frames
+ _innerGlow.frame = CGRectInset(self.bounds, 1, 1);
_backgroundLayer.frame = self.bounds;
_highlightBackgroundLayer.frame = self.bounds;
[super layoutSubviews];
}
-- (void) setHighlighted:(BOOL)highlighted
+- (void)setHighlighted:(BOOL)highlighted
{
- // set property without implicit animation
+ // Set property without implicit animation
[CATransaction begin];
[CATransaction setDisableActions:YES];
_highlightBackgroundLayer.hidden = !highlighted;
@@ -57,12 +59,9 @@ - (void) setHighlighted:(BOOL)highlighted
- (void)drawButton
{
- // Get the root layer (any UIView subclass comes with one)
+ // Get the root layer (any UIView subclass comes with one)
CALayer *layer = self.layer;
- // Make the root layer act as a mask for all sublayers
- layer.masksToBounds = YES;
-
layer.cornerRadius = 4.5f;
layer.borderWidth = 1;
layer.borderColor = [UIColor colorWithRed:0.77f green:0.43f blue:0.00f alpha:1.00f].CGColor;
@@ -101,13 +100,13 @@ - (void)drawHighlightBackgroundLayer
{
_highlightBackgroundLayer = [CAGradientLayer layer];
_highlightBackgroundLayer.colors = (@[
- (id)[UIColor colorWithRed:0.91f green:0.55f blue:0.00f alpha:1.00f].CGColor,
- (id)[UIColor colorWithRed:0.94f green:0.82f blue:0.52f alpha:1.00f].CGColor
- ]);
+ (id)[UIColor colorWithRed:0.91f green:0.55f blue:0.00f alpha:1.00f].CGColor,
+ (id)[UIColor colorWithRed:0.94f green:0.82f blue:0.52f alpha:1.00f].CGColor
+ ]);
_highlightBackgroundLayer.locations = (@[
- @0.0f,
- @1.0f
- ]);
+ @0.0f,
+ @1.0f
+ ]);
[self.layer insertSublayer:_highlightBackgroundLayer atIndex:1];
}
}
View
@@ -1,13 +1,3 @@
# Custom UIButton
-A demo app showcasing the various methods of customizing a UIButton. Requires Xcode 4.5 and iOS 6. For more deatils, check out the accompanying blog post.
-
-## modifications by kluivers
-
- - CoreGraphics is not used, removed unnecessary `- (void) drawRect:(CGRect)rect`
- - no custom event handling, uses `-(void)setHighlighted:(BOOL)highlighted` instead
- - disabled implicit animations
-
-Initialisation of layers now happens in - (id) initWithCoder:(NSCoder *)decoder, which is called after deserialization from a xib/storyboard. If you want to create the CBLayer in code another initialiser has to be added.
-
-Layer creating is kept intact and exactly the same as the original implementation.
+A demo app showcasing the various methods of customizing a UIButton. Requires Xcode 4.5 and iOS 6. For more details, check out the accompanying [blog post](http://robots.thoughtbot.com/post/33427366406/designing-for-ios-taming-uibutton).

0 comments on commit 39d4ec2

Please sign in to comment.