I have developed the application in which i want to set the background color of UIView which is already set on UIViewController.The code is below,
@implementatio
Swift 3
UIGraphicsBeginImageContextWithOptions(size, true, UIScreen.main.scale)
let context = UIGraphicsGetCurrentContext()
context?.setFillColor(UIColor.green.cgColor)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
How about this code?
- (void)drawRect:(CGRect)rect {
[super drawRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
CGRect drawRect = CGRectMake(rect.origin.x, rect.origin.y,rect.size.width, rect.size.height);
CGContextSetRGBFillColor(context, 100.0f/255.0f, 100.0f/255.0f, 100.0f/255.0f, 1.0f);
CGContextFillRect(context, drawRect);
}