One More Simple Thing I Struggle To Remember

Creating a UIImage from code. In this case a green background with a red X.

Add this to the snippets:

start a new context with a size and scale:

    UIGraphicsBeginImageContextWithOptions(imageSize, YES, 2.0);
    CGContextRef context = UIGraphicsGetCurrentContext();

Do the Core Graphics Work:

    [[UIColor greenColor] setFill];
    CGContextFillRect(context, CGRectMake(0, 0, imageSize.width, imageSize.height));
    CGFloat margin = 0.05*MAX(imageSize.width, imageSize.height);
    CGContextSetLineWidth(context, 6.0);
    CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
    CGContextSetLineCap(context, kCGLineCapRound);
    CGContextMoveToPoint(context, margin, margin);
    CGContextAddLineToPoint(context, imageSize.width - margin, imageSize.height - margin);
    CGContextMoveToPoint(context, imageSize.width - margin, margin);
    CGContextAddLineToPoint(context, margin, imageSize.height - margin);
    CGContextStrokePath(context);

Capture the image from the context and end the context:

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();