Monday, May 27, 2024
HomeiOS Developmentios - CAShapeLayer stokeLine has a border like line when theme adjustments

ios – CAShapeLayer stokeLine has a border like line when theme adjustments


I used CAShapeLayer to attract a line above a custom-made UIView. It seems to be excellent when draw for the primary time. However once I swap theme the stoke line of the CALayer comprises a border like line. I dont know why it’s drawing like this?

Earlier than it seems to be like this: https://i.postimg.cc/VLKY9k6K/mild.jpg

enter image description here

After it seems to be like this: https://i.postimg.cc/V6ZSHWsV/Darkish.png

enter image description here

// Code used to attract line
public override func draw(_ rect: CGRect) {
        let shapeLayer: CAShapeLayer = CAShapeLayer()
        let path = UIBezierPath()
        let startPoint = CGPoint(x: self.body.width / 2, y: self.body.top / 2)
        let topCenterPoint = CGPoint(x: self.body.width / 2, y: 0)
        let topLeftPoint = CGPoint(x: self.body.width, y: self.body.top / 3)
        let bottomRightPoint = CGPoint(x: self.body.width / 3, y:  self.body.top)

        path.transfer(to: startPoint)
        path.addLine(to: topCenterPoint)
        path.transfer(to: startPoint)
        path.addLine(to: topLeftPoint)
        path.transfer(to: startPoint)
        path.addLine(to: bottomRightPoint)
        path.transfer(to: startPoint)
        path.shut()
        
        shapeLayer.path = path.cgPath
        shapeLayer.strokeColor = UIColor.systemBackground.cgColor
        shapeLayer.lineWidth = 4
        self.layer.addSublayer(shapeLayer)
    }



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments