Skip to content

Commit 26d9d09

Browse files
author
Atticus Gifford
committed
CGColorRef fix for ARC
Storing the CGColorRef instead of the UIColor object was causing ARC to release the UIColor object. By the time the CGColorRef was called in some cases, the color object was gone, and the app would crash. Now using the UIColor -CGColor method on-demand instead.
1 parent 7702223 commit 26d9d09

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Classes/DDPageControl.m

+6-6
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ - (void)drawRect:(CGRect)rect
8585
CGFloat y = CGRectGetMidY(currentBounds) - diameter / 2 ;
8686

8787
// get the caller's colors it they have been set or use the defaults
88-
CGColorRef onColorCG = onColor ? onColor.CGColor : [UIColor colorWithWhite: 1.0f alpha: 1.0f].CGColor ;
89-
CGColorRef offColorCG = offColor ? offColor.CGColor : [UIColor colorWithWhite: 0.7f alpha: 0.5f].CGColor ;
88+
UIColor *drawOnColor = onColor ? onColor : [UIColor colorWithWhite: 1.0f alpha: 1.0f];
89+
UIColor *drawOffColor = offColor ? offColor : [UIColor colorWithWhite: 0.7f alpha: 0.5f];
9090

9191
// actually draw the dots
9292
for (int i = 0 ; i < numberOfPages ; i++)
@@ -97,25 +97,25 @@ - (void)drawRect:(CGRect)rect
9797
{
9898
if (type == DDPageControlTypeOnFullOffFull || type == DDPageControlTypeOnFullOffEmpty)
9999
{
100-
CGContextSetFillColorWithColor(context, onColorCG) ;
100+
CGContextSetFillColorWithColor(context, drawOnColor.CGColor) ;
101101
CGContextFillEllipseInRect(context, CGRectInset(dotRect, -0.5f, -0.5f)) ;
102102
}
103103
else
104104
{
105-
CGContextSetStrokeColorWithColor(context, onColorCG) ;
105+
CGContextSetStrokeColorWithColor(context, drawOnColor.CGColor) ;
106106
CGContextStrokeEllipseInRect(context, dotRect) ;
107107
}
108108
}
109109
else
110110
{
111111
if (type == DDPageControlTypeOnEmptyOffEmpty || type == DDPageControlTypeOnFullOffEmpty)
112112
{
113-
CGContextSetStrokeColorWithColor(context, offColorCG) ;
113+
CGContextSetStrokeColorWithColor(context, drawOffColor.CGColor) ;
114114
CGContextStrokeEllipseInRect(context, dotRect) ;
115115
}
116116
else
117117
{
118-
CGContextSetFillColorWithColor(context, offColorCG) ;
118+
CGContextSetFillColorWithColor(context, drawOffColor.CGColor) ;
119119
CGContextFillEllipseInRect(context, CGRectInset(dotRect, -0.5f, -0.5f)) ;
120120
}
121121
}

0 commit comments

Comments
 (0)