I want the bottom (not quite half) of my UIView to be a different color than the top.
I\'m wondering if I should create a CGRect and then color that? Is this along the r
You can use this code. Please change the CGRect according to your desire.
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGRect topView = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height / 2);
CGRect bottomView = CGRectMake(0, [UIScreen mainScreen].bounds.size.height / 2, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height / 2);
UIColor * grayColor = [UIColor colorWithRed:230.0/255.0 green:230.0/255.0 blue:230.0/255.0 alpha:1.0];
CGContextSetFillColorWithColor(context, grayColor.CGColor);
CGContextFillRect(context, bottomView);
CGContextSetFillColorWithColor(context, [UIColor yellowColor].CGColor);
CGContextFillRect(context, topView);
}
The following link may help you more. http://www.raywenderlich.com/32925/core-graphics-tutorial-shadows-and-gloss