美文网首页
CAShapeLayer

CAShapeLayer

作者: 翻这个墙 | 来源:发表于2017-11-23 10:55 被阅读6次

CAShapeLayer(形状图层)

  • 父类是CALayer
  • 根据路径绘制形状图层

CAShapeLayer所有独有的属性

//图形层路径
@property(nullable) CGPathRef path;
//图形层颜色
@property(nullable) CGColorRef fillColor;

@property(copy) NSString *fillRule;
//描边颜色
@property(nullable) CGColorRef strokeColor;

@property CGFloat strokeStart;
@property CGFloat strokeEnd;
//线宽
@property CGFloat lineWidth;

@property CGFloat miterLimit;

@property(copy) NSString *lineCap;

@property(copy) NSString *lineJoin;

@property CGFloat lineDashPhase;

@property(nullable, copy) NSArray<NSNumber *> *lineDashPattern;

CAShapeLayer用于图形层懒加载

- (CAShapeLayer *)shapeLayer
{
    if (_shapeLayer == nil) {
        // 可以根据路径生成图层
        CAShapeLayer *layer = [CAShapeLayer layer];
##核心代码
        //设置填充颜色
        layer.fillColor = [UIColor redColor].CGColor;

        [self.superview.layer insertSublayer:layer atIndex:0];
        _shapeLayer = layer;
##
    }
    return _shapeLayer;
}

相关文章

网友评论

      本文标题:CAShapeLayer

      本文链接:https://www.haomeiwen.com/subject/iftzvxtx.html