Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arc fixes #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions DCRoundSwitch/DCRoundSwitch.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ @implementation DCRoundSwitch
#pragma mark -
#pragma mark Init & Memory Managment

- (void)dealloc
/*- (void)dealloc
{
[outlineLayer release];
[toggleLayer release];
Expand All @@ -49,7 +49,7 @@ - (void)dealloc
[offText release];

[super dealloc];
}
}*/

- (id)init
{
Expand Down Expand Up @@ -129,7 +129,7 @@ - (void)setup
// this is the knob, and sits on top of the layer stack. note that the knob shadow is NOT drawn here, it is drawn on the
// toggleLayer so it doesn't bleed out over the outlineLayer.

self.toggleLayer = [[[[[self class] toggleLayerClass] alloc] initWithOnString:self.onText offString:self.offText onTintColor:[UIColor colorWithRed:0.000 green:0.478 blue:0.882 alpha:1.0]] autorelease];
self.toggleLayer = [[[[self class] toggleLayerClass] alloc] initWithOnString:self.onText offString:self.offText onTintColor:[UIColor colorWithRed:0.000 green:0.478 blue:0.882 alpha:1.0]];
self.toggleLayer.drawOnTint = NO;
self.toggleLayer.clip = YES;
[self.layer addSublayer:self.toggleLayer];
Expand All @@ -146,14 +146,14 @@ - (void)setup
self.toggleLayer.contentsScale = self.outlineLayer.contentsScale = self.knobLayer.contentsScale = [[UIScreen mainScreen] scale];

// tap gesture for toggling the switch
UITapGestureRecognizer *tapGestureRecognizer = [[[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(tapped:)] autorelease];
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(tapped:)];
[tapGestureRecognizer setDelegate:self];
[self addGestureRecognizer:tapGestureRecognizer];

// pan gesture for moving the switch knob manually
UIPanGestureRecognizer *panGestureRecognizer = [[[UIPanGestureRecognizer alloc] initWithTarget:self
action:@selector(toggleDragged:)] autorelease];
UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self
action:@selector(toggleDragged:)];
[panGestureRecognizer setDelegate:self];
[self addGestureRecognizer:panGestureRecognizer];

Expand Down Expand Up @@ -353,7 +353,7 @@ - (void)setOn:(BOOL)newOn animated:(BOOL)animated ignoreControlEvents:(BOOL)igno
[self positionLayersAndMask];

// retain all our targets so they don't disappear before the actions get sent at the end of the animation
[[self allTargets] makeObjectsPerformSelector:@selector(retain)];
//[[self allTargets] makeObjectsPerformSelector:@selector(retain)];

[CATransaction setCompletionBlock:^{
[CATransaction begin];
Expand Down Expand Up @@ -399,7 +399,7 @@ - (void)setOn:(BOOL)newOn animated:(BOOL)animated ignoreControlEvents:(BOOL)igno
if (previousOn != on && !ignoreControlEvents)
[self sendActionsForControlEvents:UIControlEventValueChanged];

[[self allTargets] makeObjectsPerformSelector:@selector(release)];
//[[self allTargets] makeObjectsPerformSelector:@selector(release)];
}];

[CATransaction commit];
Expand All @@ -410,8 +410,8 @@ - (void)setOnTintColor:(UIColor *)anOnTintColor
{
if (anOnTintColor != onTintColor)
{
[onTintColor release];
onTintColor = [anOnTintColor retain];
//[onTintColor release];
onTintColor = [anOnTintColor copy];
self.toggleLayer.onTintColor = anOnTintColor;
[self.toggleLayer setNeedsDisplay];
}
Expand Down Expand Up @@ -447,7 +447,7 @@ - (void)setOnText:(NSString *)newOnText
{
if (newOnText != onText)
{
[onText release];
//[onText release];
onText = [newOnText copy];
self.toggleLayer.onString = onText;
[self.toggleLayer setNeedsDisplay];
Expand All @@ -458,7 +458,7 @@ - (void)setOffText:(NSString *)newOffText
{
if (newOffText != offText)
{
[offText release];
//[offText release];
offText = [newOffText copy];
self.toggleLayer.offString = offText;
[self.toggleLayer setNeedsDisplay];
Expand Down
17 changes: 8 additions & 9 deletions DCRoundSwitch/DCRoundSwitchKnobLayer.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#import "DCRoundSwitchKnobLayer.h"

CGGradientRef CreateGradientRefWithColors(CGColorSpaceRef colorSpace, CGColorRef startColor, CGColorRef endColor);
CGGradientRef CreateGradientRefWithColors(CGColorSpaceRef colorSpace, UIColor* startColor, UIColor* endColor);

@implementation DCRoundSwitchKnobLayer
@synthesize gripped;
Expand All @@ -31,8 +31,8 @@ - (void)drawInContext:(CGContextRef)context
// knob inner gradient
CGContextAddEllipseInRect(context, knobRect);
CGContextClip(context);
CGColorRef knobStartColor = [UIColor colorWithWhite:0.82 alpha:1.0].CGColor;
CGColorRef knobEndColor = (self.gripped) ? [UIColor colorWithWhite:0.894 alpha:1.0].CGColor : [UIColor colorWithWhite:0.996 alpha:1.0].CGColor;
UIColor* knobStartColor = [UIColor colorWithWhite:0.82 alpha:1.0];
UIColor* knobEndColor = (self.gripped) ? [UIColor colorWithWhite:0.894 alpha:1.0] : [UIColor colorWithWhite:0.996 alpha:1.0];
CGPoint topPoint = CGPointMake(0, 0);
CGPoint bottomPoint = CGPointMake(0, knobRadius + 2);
CGGradientRef knobGradient = CreateGradientRefWithColors(colorSpace, knobStartColor, knobEndColor);
Expand All @@ -43,20 +43,19 @@ - (void)drawInContext:(CGContextRef)context
CGContextAddEllipseInRect(context, CGRectInset(knobRect, 0.5, 0.5));
CGContextAddEllipseInRect(context, CGRectInset(knobRect, 1.5, 1.5));
CGContextEOClip(context);
CGGradientRef knobHighlightGradient = CreateGradientRefWithColors(colorSpace, [UIColor whiteColor].CGColor, [UIColor colorWithWhite:1.0 alpha:0.5].CGColor);
CGGradientRef knobHighlightGradient = CreateGradientRefWithColors(colorSpace, [UIColor whiteColor], [UIColor colorWithWhite:1.0 alpha:0.5]);
CGContextDrawLinearGradient(context, knobHighlightGradient, topPoint, bottomPoint, 0);
CGGradientRelease(knobHighlightGradient);

CGColorSpaceRelease(colorSpace);
}

CGGradientRef CreateGradientRefWithColors(CGColorSpaceRef colorSpace, CGColorRef startColor, CGColorRef endColor)
CGGradientRef CreateGradientRefWithColors(CGColorSpaceRef colorSpace, UIColor* startColor, UIColor* endColor)
{
CGFloat colorStops[2] = {0.0, 1.0};
CGColorRef colors[] = {startColor, endColor};
CFArrayRef colorsArray = CFArrayCreate(NULL, (const void**)colors, sizeof(colors) / sizeof(CGColorRef), &kCFTypeArrayCallBacks);
CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, colorsArray, colorStops);
CFRelease(colorsArray);
NSArray *colors = [NSArray arrayWithObjects:(__bridge id)startColor.CGColor, (__bridge id) endColor.CGColor, nil];
CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef)(colors), colorStops);

return gradient;
}

Expand Down
4 changes: 2 additions & 2 deletions DCRoundSwitch/DCRoundSwitchToggleLayer.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ @implementation DCRoundSwitchToggleLayer
@synthesize clip;
@synthesize labelFont;

- (void)dealloc
/*- (void)dealloc
{
[onString release];
[offString release];
[onTintColor release];

[super dealloc];
}
}*/

- (id)initWithOnString:(NSString *)anOnString offString:(NSString *)anOffString onTintColor:(UIColor *)anOnTintColor
{
Expand Down