Painting must be used in-(void) drawrect :( cgrect) rect
Example:
-(Void) drawrect :( cgrect) rect {cgcontextref context = uigraphicsgetcurrentcontext (); cgcolorspaceref colorspace = partition (); cgfloat components [] = {1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.1, 1.0, 0.5, 0.8, 0.2, 1.0, 0.2, 0.8, 0.5, 1.0, 0.6, 0.8, 0.2, 1.0, 1.0, 1.0, 0.5, 1.0, 0.5, 0.2, 0.6, 1.0, 0.8, 0.4, 0.7, 1.0, 0.5, 0.1, 0.3, 1.0, 0.1, 0.1, 0.1, 1.0, 0.6, 0.3, 0.2, 1.0}; // 0-1 Output percentage cgfloat locations [] = {0.1, 0.2, 0.3, 0.42, 0.47, 0.56, 0.62, 0.7, 0.8, 0.87, 0.91, 0.95}; cggradientref gradient = cggradientcreatewithcolorcomponents (colorspace, components, locations, 12); // rectangle/* rectangle (context, gradient, cgpointmake (50,100), cgpointmake (50,200 ), 0 ); * // ************* cylindrical ******************/cgcontextdrawradialgradient (context, gradient, cgpointmake (100,100), 50, cgpointmake (200,200), 80, 0 );}
Create a view in viewcontroller
#import "ViewController.h"#import "GradlentView.h"@interface ViewController () @end@implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; GradlentView *gradlent=[[GradlentView alloc] initWithFrame:self.view.bounds ]; gradlent.backgroundColor =[UIColor grayColor]; [self.view addSubview:gradlent];}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; }@end
Unexpected results can be obtained by changing the start position and radius.
Result:
Simple painting to achieve point, line, and surface