How To Create Ovalin With Dashed Border In Uibezierpath

[Solved] How To Create Ovalin With Dashed Border In Uibezierpath | Objectivec - Code Explorer | yomemimo.com
Question : how to create ovalin with dashed border in uibezierpath

Answered by : successful-sandpiper-de476cjazsqs

class DashedCircleView: UIView { private var shapeLayer: CAShapeLayer = { let shapeLayer = CAShapeLayer() shapeLayer.strokeColor = UIColor.red.cgColor shapeLayer.fillColor = UIColor.clear.cgColor shapeLayer.lineWidth = 10 shapeLayer.lineCap = .round shapeLayer.lineDashPattern = [20, 60] return shapeLayer }() override init(frame: CGRect = .zero) { super.init(frame: frame) configure() } required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) configure() } override func layoutSubviews() { super.layoutSubviews() updatePath() }
}
private extension DashedCircleView { func configure() { layer.addSublayer(shapeLayer) } func updatePath() { let rect = bounds.insetBy(dx: shapeLayer.lineWidth / 2, dy: shapeLayer.lineWidth / 2) let radius = min(rect.width, rect.height) / 2 let center = CGPoint(x: rect.midX, y: rect.midY) let path = UIBezierPath(arcCenter: center, radius: radius, startAngle: 0, endAngle: .pi * 2, clockwise: true) shapeLayer.path = path.cgPath }
}

Source : https://stackoverflow.com/questions/56346091/circle-with-dash-lines-uiview | Last Update : Sun, 24 Oct 21

Question : how to create ovalin with dashed border in uibezierpath

Answered by : successful-sandpiper-de476cjazsqs

extension UIView { func addDashedCircle() { let circleLayer = CAShapeLayer() circleLayer.path = UIBezierPath(ovalIn: bounds).cgPath circleLayer.lineWidth = 2.0 circleLayer.strokeColor = UIColor.red.cgColor//border of circle circleLayer.fillColor = UIColor.white.cgColor//inside the circle circleLayer.lineJoin = .round circleLayer.lineDashPattern = [6,3] layer.addSublayer(circleLayer) }
}

Source : https://stackoverflow.com/questions/56346091/circle-with-dash-lines-uiview | Last Update : Sun, 24 Oct 21

Answers related to how to create ovalin with dashed border in uibezierpath

Code Explorer Popular Question For Objectivec