答案 0 :(得分:0)
您可以使用CAShapeLayer
作为UIView
的子图层或支持图层。 CAShapeLayer
允许您设置路径,笔触,填充等。
答案 1 :(得分:0)
// To draw an arc path
func drawCircle(view: UIView, startingAngle: CGFloat, endAngle: CGFloat) -> CAShapeLayer {
let path = UIBezierPath(arcCenter: CGPoint(x:arcViewOutlet.frame.size.width/2,y:400), radius: CGFloat((400)), startAngle: startingAngle, endAngle:endAngle, clockwise: true)
let shapeLayer = CAShapeLayer()
shapeLayer.path = path.cgPath
shapeLayer.strokeColor = UIColor.clear.cgColor
shapeLayer.fillColor = UIColor.white.cgColor
shapeLayer.lineCap = kCALineCapRound
view.layer.addSublayer(shapeLayer)
return shapeLayer
}
根据我的要求,我使用的半径为400。
给arcCentres如下。
CGPoint(x:arcViewOutlet.frame.size.width/2,y:400) //for top edge curve
CGPoint(x:arcViewOutlet.frame.size.width/2,y:-400) //for bottom edge curve
CGPoint(x:400,y:arcViewOutlet.frame.size.height/2) //for left edge curve
CGPoint(x:-400,y:arcViewOutlet.frame.size.height/2) //for right edge curve