美文网首页
转盘的简易画法

转盘的简易画法

作者: 酷酷的哀殿 | 来源:发表于2016-03-09 17:03 被阅读335次
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)
}
转盘效果图

相关文章

网友评论

      本文标题:转盘的简易画法

      本文链接:https://www.haomeiwen.com/subject/eaxtlttx.html