小编Mas*_*iYa的帖子

如何在UIView上正确设置圆周围的对象

我写了一些代码来围绕定位在自定义视图中心的圆圈放置对象,但它并不完美地围绕圆圈.我不知道代码在哪里出错了.

在此输入图像描述

这是代码:

func createObjectsAroundCircle() {

    let center = CGPointMake(bounds.width/2 ,bounds.height/2)
    let radius : CGFloat = 100
    let count = 20

    var angle = CGFloat(2 * M_PI)
    let step = CGFloat(2 * M_PI) / CGFloat(count)

    let circlePath = UIBezierPath(arcCenter: center, radius: radius, startAngle: CGFloat(0), endAngle:CGFloat(M_PI * 2), clockwise: true)

    let shapeLayer = CAShapeLayer()
    shapeLayer.path = circlePath.CGPath

    shapeLayer.fillColor = UIColor.clearColor().CGColor
    shapeLayer.strokeColor = UIColor.redColor().CGColor
    shapeLayer.lineWidth = 3.0

    self.layer.addSublayer(shapeLayer)

    // set objects around circle
    for var index = 0; index < count ; index++ …
Run Code Online (Sandbox Code Playgroud)

ios swift

12
推荐指数
1
解决办法
1006
查看次数

标签 统计

ios ×1

swift ×1