I have a UIView based class called Icon. There I want to have code similar to this:
UIView *finalView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)]; finalView.backgroundColor = [UIColor redColor]; UIGraphicsBeginImageContext(finalView.bounds.size); [finalView.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();
The problem is that I don’t want it inserted into drawRect, because it caused when my application makes each icon in a different view. How can I place this code elsewhere in the Icon class? I tried to put it in 1st place, and he gave me:
CGContextSaveGState: invalid context 0x0 CGContextSetAlpha: invalid context 0x0 CGContextSaveGState: invalid context 0x0 CGContextSetFillColorWithColor: invalid context 0x0 CGContextAddRect: invalid context 0x0 CGContextDrawPath: invalid context 0x0 CGContextRestoreGState: invalid context 0x0 CGContextRestoreGState: invalid context 0x0
Andrew
source share