1. First to introduce the properties of the next layer
-(void) initimageview{
Initialize ImageView
Uiimageview *imageview = [[Uiimageview alloc]initwithimage:[uiimage imagenamed:@ "1.jpg"]];
Set the IAMGE position to center
Imageview.frame = CGRectMake (kScreenWidth-200)/2, (kScreenHeight-200)/2, 200, 200);
Add to view
[Self.view Addsubview:imageview];
Layer
1. Set shadow color to Cgcolor for yellow type
Imageview.layer.shadowColor = [Uicolor Yellowcolor]. Cgcolor;
2. Set the shadow offset size
Imageview.layer.shadowOffset = Cgsizemake (10, 10);
3. Set the opacity of the shadow
imageview.layer.shadowOpacity = 0.5;
4. Set the fillet size
Imageview.layer.cornerRadius = 20;//Set fillet radius to 10
Force all child layers inside to support rounded effects don't show shadow effects
Imageview.layer.masksToBounds = YES;
5. Set the border
Imageview.layer.borderWidth = 5;
Imageview.layer.borderColor = [Uicolor Redcolor]. Cgcolor;
6. Set rotation, zoom clockwise rotate four per cent along the XY axis pi
Imageview.layer.transform = Catransform3dmakerotation (M_pi_4, 1, 1, 0);
Rotate four per cent of Pi clockwise along the z axis
Imageview.layer.transform = Catransform3dmakerotation (M_pi_4, 1, 1, 0);
7. Set Zoom x axis Zoom 0.5
Imageview.layer.transform = Catransform3dmakescale (0.5, 0.5, 0.5);
2. How to create a layer
Creating the framework contained in the Quartzcore framework through a class method is a cross-platform need to be added to the header file and added to the link framework
Calayer *layer = [Calayer layer];
Set the properties of a layer layer
Set Background color Gray
Layer.backgroundcolor = [Uicolor Graycolor]. Cgcolor;
Set layer Bounds
Layer.bounds = CGRectMake (0, 0, 100, 100);
/*
*position sets the position of Calayer in the parent layer with the upper-left corner of the parent layer as the origin (0,0)
The *anchorpoint Anchor Point (the anchor) determines which point of the calayer is in the position referred to by the Position property, with its upper-left corner as the origin (0,0) default (0.5,0.5) X~y The value is 0-1 lower right (1,1)
*/
Set the layer position
Layer.position = Cgpointmake (200, 200);
Set anchor points for layer
Layer.anchorpoint = Cgpointmake (0, 1);
Set the contents of layer
Layer.contents = (__bridge ID _nullable) ([UIImage imagenamed:@ "1.jpg"]. Cgimage);
Add Layers
[Self.view.layer Addsublayer:layer];
3. Custom Layers
3.1 Establish a subclass to inherit from the parent class Calayer
#import "KLayer.h"
@implementation Klayer
Implement Drawincontext method
-(void) Drawincontext: (cgcontextref) ctx{
Set color
Cgcontextsetrgbfillcolor (CTX, 1, 0, 0, 0.5);
Draw a circle and a high equal ellipse on the view
Cgcontextaddellipseinrect (CTX, cgrectmake (0, 0, 100, 100));
Draw the circle to the view
Cgcontextfillpath (CTX);
}
@end
The following methods are implemented in VIEWCONTROLLER.M
-(void) Viewdidload {
[Super Viewdidload];
[Self initlayer];
}
Initialize a custom layer
-(void) initlayer{
Klayer *layer = [Klayer layer];
Set the size of a layer
Layer.bounds = CGRectMake (0, 0, 200, 200);
Layer.anchorpoint = cgpointmake (0, 0);
The second method of proxy
Layer.delegate = self;//Without protocol any object can be a proxy
[Layer setneedsdisplay];//must call this method layer will not display
Add Layers
[Self.view.layer Addsublayer:layer];
}
The way to implement this agent through the broker
#pragma mark Layer Agent method
You can draw layers in this proxy method
-(void) Drawlayer: (Calayer *) layer Incontext: (cgcontextref) ctx{
Set color
Cgcontextsetrgbfillcolor (CTX, 0, 0, 1, 1);
Draw a circle and a high equal ellipse on the view
Cgcontextaddellipseinrect (CTX, cgrectmake (0, 0, 100, 100));
Draw the circle to the view
Cgcontextfillpath (CTX);
}