swift
1import UIKit 2class ViewController: UIViewController { 3 4 override func viewDidLoad() { 5 super.viewDidLoad() 6 // Do any additional setup after loading the view. 7 8 var colorArr:[UIColor] = [] 9 for i in 1 ..< 33{ 10 let theta = CGFloat(i) * CGFloat.pi / 66 11 colorArr.append(UIColor(red: cos(theta), green: sin(theta), blue: 0, alpha: 1)) 12 } 13 14 for i in 1 ..< 33{ 15 let theta = CGFloat(i) * CGFloat.pi / 66 16 colorArr.append(UIColor(red: 0, green: cos(theta), blue: sin(theta), alpha: 1)) 17 } 18 19 for i in 1 ..< 33{ 20 let theta = CGFloat(i) * CGFloat.pi / 66 21 colorArr.append(UIColor(red: sin(theta), green: 0, blue: cos(theta), alpha: 1)) 22 } 23 24 let radius = self.view.bounds.width / 4 25 let center = self.view.center 26 27 let theta = 2 * CGFloat.pi / CGFloat(colorArr.count) 28 29 for i in 0 ..< colorArr.count{ 30 let colorView = UIView(frame: CGRect(x: 0, y: 0, width: 30, height: 30)) 31 colorView.backgroundColor = colorArr[i] 32 colorView.center.x = center.x + radius * cos(CGFloat(i) * theta) 33 colorView.center.y = center.y + radius * sin(CGFloat(i) * theta) 34 view.addSubview(colorView) 35 } 36 37 } 38} 39
UIView99個で円のグラデーションを作るときになぜlet theta = CGFloat(i) * CGFloat.pi / 66
ここは66で割るのでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。