#import "ViewController.h"@interfaceViewcontroller () @property (weak, nonatomic) Iboutlet UIView*Redview, @property (weak, nonatomic) Iboutlet Uiimageview*Imagev;@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; //additional setup after loading the view, typically from a nib.}-(void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (Uievent *)Event { //set the color of the shadowSelf.imageV.layer.shadowColor =[Uicolor Bluecolor]. Cgcolor; //set the opacity of the shadow: 0 is completely transparent and 1 is opaqueSelf.imageV.layer.shadowOpacity =1; //Set the shadow offset to a wide height offset, and a positive number to the right.Self.imageV.layer.shadowOffset = Cgsizemake (Ten,Ten); //set the blur radius of the shadowSelf.imageV.layer.shadowRadius =5; //border width, go inside.Self.imageV.layer.borderWidth =2; Self.imageV.layer.borderColor=[Uicolor Greencolor]. Cgcolor; /** * 1:image is not on the layear layer, but on the contents of layear, the fillet effect is on the layear layer, and does not affect the image on the contents, in order to contact the layer and contents, You must set the Self.imageV.layer.masksToBounds, that is, more than the root layer is the layear layer of the portion of the cut off, so imageview to set the fillet effect must be added self.imageV.layer.masksToBounds, and Uivi EW can be used without setting 2: Set the Round effect: let the Uiimageview fillet Cornerradius equal to half the width of the Uiimageview*/ //Set rounded cornersSelf.imageV.layer.cornerRadius = -; //Cut out anything beyond the root layer (the layer UIView comes from, we call it the root layer)Self.imageV.layer.masksToBounds =YES; NSLog (@"%@", self.imageV.layer.contents);}- (void) Uiviewlayer {//set the color of the shadowSelf.redView.layer.shadowColor =[Uicolor Bluecolor]. Cgcolor; //set the opacity of a shadowSelf.redView.layer.shadowOpacity =1; Self.redView.layer.shadowOffset= Cgsizemake (- -, - -); //set the blur radius of the shadowSelf.redView.layer.shadowRadius =5; //border width, go inside.Self.redView.layer.borderWidth =2; Self.redView.layer.borderColor=[Uicolor Greencolor]. Cgcolor; //Set rounded cornersSelf.redView.layer.cornerRadius = -;}@end
1.CALayer Introduction:
Calayer We call it a layer.
Within each uiview there is a layer such a property.
UIView is able to display because it has this layer in it, it has the function of display.
We can easily adjust some of the appearance properties of the UIView by manipulating the Calayer object.
You can set shadows, fillets, borders and so on for UIView ...
2. The operation layer changes the UIView appearance.
2.1. Setting shadows
The default layer is shaded, except that it is transparent.
_redview.layer.shadowopacity = 1;
set the rounded corners of a shadow
_redview.layer.shadowradius =10;
set the color of the shadow, convert Uikit to Coregraphics frame, start with. CG
_redview.layer.shadowcolor = [Uicolor Bluecolor]. Cgcolor;
2.2. Setting the Border
set the layer border to use coregraphics cgcolorref in the layer
_redview.layer.bordercolor = [Uicolor Whitecolor]. Cgcolor;
_redview.layer.borderwidth = 2;
2.3. Setting rounded corners
the fillet radius of the layer, which is half the width of the fillet, is a circle
_redview.layer.cornerradius =;
3. The operation layer changes the appearance of the Uiimageview.
set a graphic border
_imageview.layer.borderwidth = 2;
_imageview.layer.bordercolor = [Uicolor Whitecolor]. Cgcolor;
Set the fillet radius of a picture
_imageview.layer.cornerradius = 50;
Crop, cut out of parts of the cropping area
_imageview.layer.maskstobounds = YES;
Note: The image in Uiimageview is not directly added to the layer. This is added to the contents in the layers layer.
we set all the properties of the layer and it only acts on top of the layer. It doesn't work on contents. So we can't see the rounded effect of the picture.
You want the image to have rounded corners. You can set the Maskstobounds property to Yes,
when set to Yes, it cuts out everything beyond the root layer.
iOS development layer and core animation one: understanding of Layer Calayer