1

我在中心有一张照片,我想在一定程度上将按钮阵列添加到视图中。我希望第一个按钮位于 2pi 处,并且每个按钮距离第一个按钮为 2pi/数组中的对象数。最后,按钮将创建一个圆形路径。以下是我到目前为止所拥有的。我可以得到起点,但我被困在如何为每个按钮添加 2pi/对象弧度数。圆的中心位于视图的中心。

extension Int {
var degreesToRadians : CGFloat {
    return CGFloat(self) * CGFloat(M_PI) / 180.0
    }
}


@IBOutlet weak var currentuserpic: UIButton!

var userbutton = [UIButton]()
var upimage = [UIImage]()

  func locationsSet(){
    for users in upimage{
        let userbutton = UIButton()
        let degree = CGFloat(360/self.upimage.count)
        userbutton.addTarget(self, action: "buttonAction:", forControlEvents: .TouchUpInside)
        userbutton.frame = CGRectMake(100, 100, 50, 50)
        userbutton.layer.cornerRadius = userbutton.frame.size.width/2
        userbutton.clipsToBounds = true
        userbutton.setImage(users, forState: .Normal)

        let buttonWidth = userbutton.frame.width
        let buttonHeight = userbutton.frame.height

        // Find the width and height of the enclosing view
        let viewWidth = self.view.bounds.width
        let viewHeight = self.view.bounds.height


        let xwidth = viewWidth - buttonWidth
        let yheight = viewHeight - buttonHeight


        let pointx = (self.view.bounds.width/2.0) + (currentuserpic.frame.size.width/2.0) + 50
        let pointy = self.view.bounds.height/2.0


        userbutton.center.x = pointx

        userbutton.center.y = pointy

        print(pointx)
        print(pointy)

        self.userbutton.append(userbutton)
        print("called")
        self.view.addSubview(userbutton)


    }
}
4

0 回答 0