CALayer *superLayer=self.view.layer;
//創(chuàng)建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內(nèi)容
UIImage *image =[UIImage imageNamed:@"b"];
subLayer.contents =(__bridge id)(image.CGImage);
//超出范圍剪裁
subLayer.masksToBounds =YES;
//邊框顏色
subLayer.borderColor=[UIColor yellowColor].CGColor;
//邊框大小
subLayer.borderWidth =5;
// 陰影
// 陰影和邊界剪裁是不能同時使用的壮池,因為陰影本身就是渲染到邊界外面的
//再從新創(chuàng)建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];