CALayer,,,CATextLayer,,,CAShapeLayer,, CAGradientLayer
CALayer
//获得根图层
CALayer *layer = [[CALayer alloc]init]; (CATextLayer 可以填加文字)
layer.backgroundColor = [UIColor blueColor].CGColor;
layer.position = CGPointMake(ScreenWidth/2.0, ScreenHeight/2.0);
layer.bounds = CGRectMake(0, 0, 40, 40);
layer.cornerRadius = 40/2.0;
layer.shadowColor=[UIColor grayColor].CGColor;
layer.shadowOffset=CGSizeMake(2, 2);
layer.shadowOpacity=0.9;
layer.contents = (__bridge id)image.CGImage; //添加图片
layer.contentsGravity = kCAGravityResizeAspect; //图片的展示方式
[self.view.layer addSublayer:layer];
//获取到Layer
CALayer *layer = self.view.layer.sublayers.firstObject;
CATextLayer
CATextLayer *lary = [CATextLayer layer];
lary.string = @"dasfasa";
lary.bounds = CGRectMake(0, 0, 320, 20);
lary.font = CFBridgingRetain(@"HiraKakuProN-W3");//字体的名字 不是 UIFont
lary.fontSize = 12.f;//字体的大小
lary.wrapped = YES;//默认为No. 当Yes时,字符串自动适应layer的bounds大小
lary.alignmentMode = kCAAlignmentCenter;//字体的对齐方式
lary.position = CGPointMake(160, 410);//layer在view的位置 适用于跟随摸一个不固定长的的控件后面需要的
lary.contentsScale = [UIScreen mainScreen].scale;//解决文字模糊 以Retina方式来渲染,防止画出来的文本像素化
lary.foregroundColor =[UIColor redColor].CGColor;//字体的颜色 文本颜色
[self.view.layer addSublayer:lary];
CAShapeLayer (对UIView进行不规则裁切, 与UIBezierPath相结合使用,)
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 64, 100, 100)];
// UIBezierPath *path = [UIBezierPath bezierPath];
// [path moveToPoint:point1];
// [path addLineToPoint:point2];
// [path addLineToPoint:point3];
// [path closePath];
// view.layer.mask = layer; //对View进行不规则裁切
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.frame = CGRectMake(0, 0, 100, 100);
shapeLayer.strokeEnd = 0.7f;
shapeLayer.strokeStart = 0.1f;
shapeLayer.path = path.CGPath;
shapeLayer.fillColor = [UIColor clearColor].CGColor;
shapeLayer.lineWidth = 2.0f;
shapeLayer.strokeColor = [UIColor blueColor].CGColor;
[self.view.layer addSublayer:shapeLayer];
CAGradientLayer 渐变
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.frame = self.view.bounds;
[self.view.layer addSublayer:gradientLayer];
gradientLayer.colors = @[(__bridge id)[UIColor clearColor].CGColor, (__bridge id)[UIColor whiteColor].CGColor];
gradientLayer.startPoint = CGPointMake(0, 0);
gradientLayer.endPoint = CGPointMake(0, 1);