快速按顺序绘制多个圆圈

问题描述 投票:0回答:2

[如何在Swift中按顺序绘制多个圆,当用户在TextField中输入数字时,我想在左侧的视图中绘制圆的数量:

示例:enter image description here

到目前为止,这是我的代码:

func drawCircleInsideView(view: UIView, count: Int){
    let halfSize:CGFloat = min(view.bounds.size.width/2, view.bounds.size.height/2) / CGFloat(count)
    let desiredLineWidth:CGFloat = 1
    var i = 0
    var lastPosition = 0
    while i <= count {
      print(“THIAGO: “, i)
      i = i + 1
      let circlePath = UIBezierPath(
          arcCenter: CGPoint(x:halfSize,y:halfSize),
          radius: CGFloat( halfSize - (desiredLineWidth/2) ),
          startAngle: CGFloat(0),
          endAngle:CGFloat(Double.pi * 2),
          clockwise: true)
      let shapeLayer = CAShapeLayer()
      shapeLayer.path = circlePath.cgPath
      shapeLayer.fillColor = UIColor.green.cgColor
      shapeLayer.strokeColor = UIColor.green.cgColor
      shapeLayer.lineWidth = desiredLineWidth
      view.layer.addSublayer(shapeLayer)
      lastPosition = lastPosition + 2
    }
  }
ios swift uiview drawing uibezierpath
2个回答
1
投票

您需要使用i ..来改变圆心


1
投票

您可以使用视图和约束:

© www.soinside.com 2019 - 2024. All rights reserved.