I hope I am able to explain my actual problem. I have got a navigation controller whose root controller is a Table view controller. I want to paint the Table view controller background by adding a gradient sub view as a background. Every thing works well but the gradient background is now apply just under the navigation bar, even if this is translucent. In fact I see it as translucent but in this configuration, the background just start below the navigation bar. I want also the navigation bar be gradient like the background below. How can I do it? Is my question clear enough? Thank you very much.
[self drawGradientBackground];
- (void)drawGradientBackground
{
self.view.backgroundColor = [UIColor clearColor];
RMABackGround *background = [[RMABackGround alloc] initWithFrame:self.view.bounds];
background.gradientColors = @[[UIColor colorWithRed:52/255.0f green:153/255.0f blue:55/255.0f alpha:1.0f], [UIColor colorWithRed:53/255.0f green:168/255.0f blue:224/255.0f alpha:1.0f]];
[self.view addSubview:background];
}
Into RMABackGround class:
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
NSMutableArray *colors = [NSMutableArray arrayWithCapacity:[self.gradientColors count]];
[self.gradientColors enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if ([obj isKindOfClass:[UIColor class]]) {
[colors addObject:(__bridge id)[obj CGColor]];
} else if (CFGetTypeID((__bridge void *)obj) == CGColorGetTypeID()) {
[colors addObject:obj];
} else {
@throw [NSException exceptionWithName:@"CRGradientLabelError"
reason:@"Object in gradientColors array is not a UIColor or CGColorRef"
userInfo:NULL];
}
}];
CGContextSaveGState(context);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextTranslateCTM(context, 0, -rect.size.height);
CGGradientRef gradient = CGGradientCreateWithColors(NULL, (__bridge CFArrayRef)colors, NULL);
CGPoint startPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMinY(rect));
CGPoint endPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMaxY(rect));
CGContextDrawLinearGradient(context, gradient, startPoint, endPoint,
kCGGradientDrawsAfterEndLocation | kCGGradientDrawsBeforeStartLocation);
CGGradientRelease(gradient);
CGContextRestoreGState(context);
[super drawRect:rect];
}