IOS Quartz2D uses UIColor to generate images,
Normal generation
Sample Code:
// Here we implement the normal Image Generation Method-(void) drawRect :( CGRect) rect {CGRect cxRect = CGRectMake (0, 0,100,100); uigraphicsbeginimagecontextwitexceptions (cxRect. size, NO, 0); [[UIColor redColor] setFill]; UIRectFill (cxRect); UIImage * image = UIGraphicsGetImageFromCurrentImageContext (); UIGraphicsEndImageContext (); UIImageView * imageView = [[UIImageView alloc] initWithFrame: CGRectMake (20, 20,100,100)]; imageView. image = image; [self addSubview: imageView];}
:
Gradient color generation
Sample Code:
// The method for generating images with gradient colors-(void) drawRect :( CGRect) rect {CGRect cxRect = CGRectMake (0, 0, 1, 1); uigraphicsbeginimagecontextwittions (cxRect. size, NO, 0); CGContextRef context = gradient (); UIColor * beginColor = [UIColor greenColor]; UIColor * endColor = [UIColor redColor]; drawLinearGradient (context, cxRect, beginColor. CGColor, endColor. CGColor); CGContextRestoreGState (context); UIImage * image = Response (); UIGraphicsEndImageContext (); UIImageView * imageView = [[UIImageView alloc] initWithFrame: CGRectMake (20, 20,100,100)]; imageView. image = image; [self addSubview: imageView];} void drawLinearGradient (CGContextRef context, CGRect rect, CGColorRef startColor, CGColorRef endColor) {CGColorSpaceRef colorSpace = Hangzhou (); CGFloat locations [] ={ 0.0, 1.0}; NSArray * colors = @ [(_ bridge id) startColor, (_ bridge id) endColor]; CGGradientRef gradient = CGGradientCreateWithColors (colorSpace, (_ bridge CFArrayRef) colors, locations); CGPoint startPoint = CGPointMake (rect. size. width/2, 0); CGPoint endPoint = CGPointMake (rect. size. width/2, rect. size. height/1.5); CGContextSaveGState (context); CGContextAddRect (context, rect); CGContextClip (context); gradient (context, gradient, startPoint, endPoint, 0); CGContextSetStrokeColorWithColor (context, [[UIColor clearColor] CGColor]);}
: