////VIEWCONTROLLER.M//01-calayer Create////Created by Mac on 16/4/18.//copyright©2016 Year Mac. All rights reserved.///*1. Position: Determines the relative offset of the current layer's anchor point to the parent view layer coordinates to the origin, finds the anchor position on the current layer, and aligns the two to 2. Draw a straight line trilogy: Create a variable path (pathcreatemutable): Add to Context (Addpath): Start drawing (drawpath) pathway Phase 2: Starting point determination, property setting (line width and color)*/#import "ViewController.h"@interfaceViewcontroller ()@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; [Self creatcalayer];}/** * Create Calayer*//*-(void) Creatcalayer {calayer *layer = [Calayer layer]; Layer.bounds = CGRectMake (0, 0, 200, 200); Position and anchor points determine position, bounds determines size//Layer.frame = CGRectMake (0, 0, 200, 200); The Frame property's constraint on the layer is only a size constraint, and the position is determined by anchorpoint Layer.backgroundcolor = [Uicolor Orangecolor]. Cgcolor; [Self.view.layer Addsublayer:layer]; Layer.position = Cgpointmake (100, 300); Layer.anchorpoint = Cgpointzero;}*/- (void) Creatcalayer {calayer*layer =[Calayer layer]; Layer.bounds= CGRectMake (0,0, $, $);//position and anchor points determine position, bounds determines sizeLayer.backgroundcolor =[Uicolor Orangecolor]. Cgcolor; Layer.anchorpoint=Cgpointzero; Layer.Delegate=Self ; [Self.view.layer Addsublayer:layer]; [Layer Setneedsdisplay];}/** * Layer proxy method. This method can be called only if the agent is set*/- (void) Drawlayer: (Calayer *) layer Incontext: (cgcontextref) CTX {//NSLog (@ "Hahahha");cgmutablepathref Path= Cgpathcreatemutable ();//1. Draw a line in the layer path getscgpathmovetopoint (Path, NULL, -, -);//2. Starting pointCgpathaddlinetopoint (Path, NULL, Max, Max);//Connection Point//[[Uicolor Yellowcolor] setstroke];Cgcontextsetrgbstrokecolor (CTX,0,1,1,1);//3. Stoke Line ColorCgcontextsetlinewidth (CTX,5);//line widthCgcontextaddpath (CTX, path);//4. Path added to the contextCgcontextdrawpath (CTX, Kcgpathstroke);//5. Draw}
01-calayer Create + proxy settings