CALayer *superLayer=self.view.layer;
//创建CALayer
CALayer *subLayer =[CALayer layer];
//添加到父图层
[superLayer addSublayer:subLayer];
//尺寸
subLayer.bounds =CGRectMake(0, 0, 200, 200);
//颜色
subLayer.backgroundColor =[UIColor greenColor].CGColor;
//位置
subLayer.position=CGPointMake(100, 100);
//锚点
subLayer.anchorPoint =CGPointMake(0 , 0);
//圆角
subLayer.cornerRadius =100;
//context内容
UIImage *image =[UIImage imageNamed:@"b"];
subLayer.contents =(__bridge id)(image.CGImage);
//超出范围剪裁
subLayer.masksToBounds =YES;
//边框颜色
subLayer.borderColor=[UIColor yellowColor].CGColor;
//边框大小
subLayer.borderWidth =5;
// 阴影
// 阴影和边界剪裁是不能同时使用的,因为阴影本身就是渲染到边界外面的
//再从新创建CALyer,这样可以添加阴影
CALayer *shadowLayer =[CALayer layer];
shadowLayer.bounds =subLayer.bounds;
shadowLayer.position =subLayer.position;
shadowLayer.anchorPoint = CGPointMake(0, 0);
//圆角
shadowLayer.cornerRadius =100;
// CALayer的默认背景色不是白色,而是透明色
shadowLayer.backgroundColor =[UIColor whiteColor].CGColor;
//阴影颜色
shadowLayer.shadowColor =[UIColor grayColor].CGColor;
//阴影偏移量
shadowLayer.shadowOffset =CGSizeMake(10, 10);
//阴影不透明度
shadowLayer.shadowOpacity =1;
//添加视图
[superLayer insertSublayer:shadowLayer below:subLayer];
//形变
//位移01
subLayer.transform =CATransform3DMakeTranslation(-100, 100, 0);
//位移02
subLayer.transform =CATransform3DMakeTranslation(100, -100, 0);
//放大,缩小
subLayer.transform=CATransform3DMakeScale(.5, .5, .5);
//旋转 (-1,0,1) 倒着转,不转,正着转;旋转中心以锚点为中心点
subLayer.transform =CATransform3DMakeRotation(-M_PI_4, -1, 0, 1);
CALayer *transLayer =[CALayer layer];
transLayer.bounds =CGRectMake(0, 0, 100, 100);
transLayer.position =CGPointMake(100, 100);
transLayer.backgroundColor =[UIColor brownColor].CGColor;
[self.view.layer addSublayer:transLayer];
//近大远小
CATransform3D trans =CATransform3DIdentity;
trans.m34 =-1/800.f;
subLayer.transform =trans;
trans =CATransform3DRotate(trans, M_PI_4, 0, -1, -1);
transLayer.transform =trans;
CALayer *textLayer =[CALayer layer];
textLayer.bounds =transLayer.bounds;
textLayer.position =transLayer.position;
textLayer.backgroundColor =[UIColor blueColor].CGColor;
[self.view.layer insertSublayer:textLayer below:transLayer];