gpt4 book ai didi

ios - 在曲线形状图层上绘制边框

转载 作者:行者123 更新时间:2023-11-29 00:15:50 25 4
gpt4 key购买 nike

我已经看过这个How to get a border on UIBezierPath

我想在曲线上画边框

我用下面的方法画了曲线

func drawCurve(from startPoint: CGPoint, to endPoint: CGPoint, controlPoint: CGPoint) {

var bezierPath = UIBezierPath()
bezierPath.move(to: startPoint)
// bezierPath.addQuadCurve(to: endPoint, controlPoint: CGPoint
bezierPath.addLine(to: controlPoint)
bezierPath.addLine(to: endPoint);


bezierPath = bezierPath.bezierCardinal(withTension: 2.06)
curveSize = bezierPath.bounds
let strokeColor = UIColor.white
if curveLayer != nil {
curveLayer?.removeFromSuperlayer()
curveLayer = nil
}
curveLayer = CAShapeLayer()
curveLayer?.lineWidth = 1.0 / self.zoomScale
curveLayer?.fillColor = UIColor.clear.cgColor
curveLayer?.path = bezierPath.cgPath
curveLayer?.strokeColor = strokeColor.cgColor
viewBase.layer.addSublayer(curveLayer!)
}

我试着把

    curveLayer?.borderWidth = 1.0
curveLayer?.borderColor = UIColor.yellow.cgColor

但它不会在(框内)周围绘制边框

enter image description here

最佳答案

尝试下面的代码-

lineShapeBorder = CAShapeLayer()
lineShapeBorder.zPosition = 0.0
lineShapeBorder.strokeColor = UIColor.blue.cgColor
lineShapeBorder.lineWidth = 25
lineShapeBorder.lineCap = kCALineCapRound
lineShapeBorder.lineJoin = kCALineJoinRound
lineShapeFill = CAShapeLayer()
lineShapeBorder.addSublayer(lineShapeFill)
lineShapeFill.zPosition = 0.0
lineShapeFill.strokeColor = UIColor.green.cgColor
lineShapeFill.lineWidth = 20.0
lineShapeFill.lineCap = kCALineCapRound
lineShapeFill.lineJoin = kCALineJoinRound
// ...
var path = UIBezierPath()
path.move(to: lineStart)
path.addLine(to: lineEnd)
lineShapeFill.path = path.cgPath
lineShapeBorder.path = lineShapeFill.path

希望对您有所帮助!

关于ios - 在曲线形状图层上绘制边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45351372/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com