Normal Build
Example code:
Here the way to achieve the normal generation of pictures-(void) DrawRect: (cgrect) rect { CGRect cxrect = CGRectMake (0, 0,.); Uigraphicsbeginimagecontextwithoptions (cxrect.size, NO, 0); [[Uicolor Redcolor] setfill]; Uirectfill (cxrect); UIImage * image = Uigraphicsgetimagefromcurrentimagecontext (); Uigraphicsendimagecontext (); Uiimageview * ImageView = [[Uiimageview alloc]initwithframe:cgrectmake (+, +, +)]; Imageview.image = image; [Self addsubview:imageview];}
:
Gradient Color generation
Example code:
Here is the way to implement the gradient color generation picture-(void) DrawRect: (cgrect) rect {cgrect cxrect = CGRectMake (0, 0, 1, 1); Uigraphicsbeginimagecontextwithoptions (cxrect.size, NO, 0); Cgcontextref context = Uigraphicsgetcurrentcontext (); Uicolor * Begincolor = [Uicolor Greencolor]; Uicolor * EndColor = [Uicolor Redcolor]; Drawlineargradient (context, Cxrect, Begincolor.cgcolor, Endcolor.cgcolor); Cgcontextrestoregstate (context); UIImage *image = Uigraphicsgetimagefromcurrentimagecontext (); 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 = Cgcolorspacecreatedevicergb (); 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); Cgcontextdrawlineargradient (context, gradient, startPoint, endPoint, 0); Cgcontextsetstrokecolorwithcolor (context, [[Uicolor Clearcolor] cgcolor]);}
:
IOS quartz2d generating pictures from Uicolor