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)
}
转盘效果图
网友评论