import Foundation
import UIKit
import XCPlayground
let circleView = UIView(frame: CGRectMake(0,0,1000,1000))
circleView.backgroundColor = UIColor.whiteColor()
XCPlaygroundPage.currentPage.liveView = circleView
//按鈕數量
let count = 9
//距離中心的距離
let distance = 100.0
for i in 1...count{
let button = UIButton(frame: CGRectMake(400,400,80,80))
button.backgroundColor = UIColor.orangeColor()
button.layer.cornerRadius=40
button.setTitleColor(UIColor.redColor(), forState: .Normal)
button.setTitle("按鈕\(i)", forState: .Normal)
let an = 2*M_PI*Double(i)/Double(count)
let tx = CGFloat(distance*sin(an))
let ty = CGFloat(distance*cos(an))
let rotationAndPerspectiveTransform = CATransform3DMakeTranslation(tx, ty, 0)
button.layer.transform = rotationAndPerspectiveTransform
circleView.addSubview(button)
}
轉盤效果圖