如何在每x度添加一个按钮?

时间:2015-12-11 18:18:02

标签: ios swift degrees radians

我在中心有一张照片,我希望在某种程度上将按钮数组添加到视图中。我希望第一个按钮为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)


    }
}

0 个答案:

没有答案