Reputation: 4832
I have a custom UITableViewCell
class, and within that I've overridden the drawRect
method to produce a nice gradient background. However, I only want the gradient for one case, and I switch using an if
statement.
Is there a better way to write this?
- (void) drawRect:(CGRect)rect {
// Setup gradient
CGContextRef context = UIGraphicsGetCurrentContext();
CGColorRef topColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0].CGColor;
CGColorRef bottomColor = [UIColor colorWithRed:240.0/255.0 green:240.0/255.0 blue:240.0/255.0 alpha:1.0].CGColor;
CGRect cellRect = self.bounds;
if (!isDescription)
drawLinearGradient(context, cellRect, topColor, bottomColor);
else
drawLinearGradient(context, cellRect, bottomColor, bottomColor);
}
It seems silly drawing a gradient when I want a solid. Any suggestions?
Upvotes: 0
Views: 744
Reputation: 5128
Try looking at CGContextFillRect here: http://developer.apple.com/library/IOs/documentation/GraphicsImaging/Reference/CGContext/Reference/reference.html
You will need to set bottomColor as the fill color first
Upvotes: 1