Skip to content

Commit

Permalink
fixed disabled bug, fixed memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
jessesquires committed Apr 2, 2013
1 parent 20a592d commit 839de55
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions BButton/BButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ - (void)setGradientEnabled:(BOOL)enabled;
@implementation BButton

@synthesize color;
@synthesize gradient;
@synthesize shouldShowDisabled;

#pragma mark - Initialization
- (void)setup
Expand Down Expand Up @@ -162,6 +164,24 @@ - (void)setColor:(UIColor *)newColor
[self setNeedsDisplay];
}

- (void)setShouldShowDisabled:(BOOL)show
{
shouldShowDisabled = show;

if(show) {
if([self.color isLightColor])
[self setTitleColor:[UIColor colorWithWhite:0.4f alpha:0.5f] forState:UIControlStateDisabled];
else
[self setTitleColor:[UIColor colorWithWhite:1.0f alpha:0.5f] forState:UIControlStateDisabled];
}
else {
if([self.color isLightColor])
[self setTitleColor:[UIColor blackColor] forState:UIControlStateDisabled];
else
[self setTitleColor:[UIColor whiteColor] forState:UIControlStateDisabled];
}
}

#pragma mark - BButton
- (void)setType:(BButtonType)type
{
Expand Down Expand Up @@ -294,16 +314,12 @@ - (void)drawRect:(CGRect)rect
- (void)setGradientEnabled:(BOOL)enabled
{
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
UIColor *topColor = [self.color lightenColorWithValue:0.12f];

if(!enabled) {
topColor = [self.color darkenColorWithValue:0.12f];
}
UIColor *topColor = enabled ? [self.color lightenColorWithValue:0.12f] : [self.color darkenColorWithValue:0.12f];

NSArray *newGradientColors = [NSArray arrayWithObjects:(id)topColor.CGColor, (id)self.color.CGColor, nil];
CGFloat newGradientLocations[] = {0.0f, 1.0f};

self.gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef)newGradientColors, newGradientLocations);
gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef)newGradientColors, newGradientLocations);
CGColorSpaceRelease(colorSpace);
}

Expand Down

0 comments on commit 839de55

Please sign in to comment.