Skip to content

Commit

Permalink
FIX: ensure gradient colors aren't nil before accessing
Browse files Browse the repository at this point in the history
  • Loading branch information
u10int committed Jan 11, 2015
1 parent 7ea7685 commit 47f2165
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions URBSegmentedControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -790,9 +790,12 @@ - (UIImage *)selectedBackgroundImage {
UIColor *segmentHighlight = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.7];

// gradients
NSArray *segmentGradientColors = @[(id)segmentGradientTopColor.CGColor, (id)segmentGradientBottomColor.CGColor];
CGFloat segmentGradientLocations[] = {0, 1};
CGGradientRef segmentGradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef)segmentGradientColors, segmentGradientLocations);
CGGradientRef segmentGradient = NULL;
if (segmentGradientTopColor && segmentGradientBottomColor) {
NSArray *segmentGradientColors = @[(id)segmentGradientTopColor.CGColor, (id)segmentGradientBottomColor.CGColor];
CGFloat segmentGradientLocations[] = {0, 1};
segmentGradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef)segmentGradientColors, segmentGradientLocations);
}

// shadows
CGSize segmentHighlightOffset = CGSizeMake(0.1, 1.1);
Expand All @@ -813,10 +816,12 @@ - (UIImage *)selectedBackgroundImage {
UIBezierPath *segmentBasePath = [UIBezierPath bezierPathWithRoundedRect:segmentBaseRect cornerRadius:radius];
CGContextSaveGState(context);
[segmentBasePath addClip];
CGContextDrawLinearGradient(context, segmentGradient,
CGPointMake(CGRectGetMidX(segmentBaseRect), CGRectGetMinY(segmentBaseRect)),
CGPointMake(CGRectGetMidX(segmentBaseRect), CGRectGetMaxY(segmentBaseRect)),
0);
if (segmentGradient) {
CGContextDrawLinearGradient(context, segmentGradient,
CGPointMake(CGRectGetMidX(segmentBaseRect), CGRectGetMinY(segmentBaseRect)),
CGPointMake(CGRectGetMidX(segmentBaseRect), CGRectGetMaxY(segmentBaseRect)),
0);
}
CGContextRestoreGState(context);

// inner shadow
Expand Down

0 comments on commit 47f2165

Please sign in to comment.