CAShapeLayer带边框和填充颜色和圆角 [英] CAShapeLayer with border and fill color and rounding

查看:1382
本文介绍了CAShapeLayer带边框和填充颜色和圆角的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用CAShapeLayer绘制具有边框颜色,边框宽度和填充颜色的线条?

How do I use CAShapeLayer to draw a line that has both a border color, border width and fill color?

这是我尝试过的,但它只是永远是蓝色...

Here's what I've tried, but it's only ever blue...

self.lineShape.strokeColor = [UIColor blueColor].CGColor;
self.lineShape.fillColor = [UIColor greenColor].CGColor;
self.lineShape.lineWidth = 100;
self.lineShape.lineCap = kCALineCapRound;
self.lineShape.lineJoin = kCALineJoinRound;
UIBezierPath* path = [UIBezierPath bezierPath];
[path moveToPoint:self.lineStart];
[path addLineToPoint:self.lineEnd];
self.lineShape.path = path.CGPath;


推荐答案

    self.lineShapeBorder = [[CAShapeLayer alloc] init];
    self.lineShapeBorder.zPosition = 0.0f;
    self.lineShapeBorder.strokeColor = [UIColor blueColor].CGColor;
    self.lineShapeBorder.lineWidth = 25;
    self.lineShapeBorder.lineCap = kCALineCapRound;
    self.lineShapeBorder.lineJoin = kCALineJoinRound;

    self.lineShapeFill = [[CAShapeLayer alloc] init];
    [self.lineShapeBorder addSublayer:self.lineShapeFill];
    self.lineShapeFill.zPosition = 0.0f;
    self.lineShapeFill.strokeColor = [UIColor greenColor].CGColor;
    self.lineShapeFill.lineWidth = 20.0f;
    self.lineShapeFill.lineCap = kCALineCapRound;
    self.lineShapeFill.lineJoin = kCALineJoinRound;

// ...

    UIBezierPath* path = [UIBezierPath bezierPath];
    [path moveToPoint:self.lineStart];
    [path addLineToPoint:self.lineEnd];
    self.lineShapeBorder.path = self.lineShapeFill.path = path.CGPath;

这篇关于CAShapeLayer带边框和填充颜色和圆角的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆