調色大師
Published in
3 min readAug 1, 2018
Star War 光劍
這次的調色大師app選用Star War為主題
其中有一個特別的“天選之劍”
就是運用了剛學到的亂數
運行畫面如下
程式碼
import UIKitclass ViewController: UIViewController {@IBOutlet weak var blueValueLabel: UILabel!@IBOutlet weak var greenValueLabel: UILabel!@IBOutlet weak var redValueLabel: UILabel!@IBOutlet weak var Redslider: UISlider!@IBOutlet weak var Greenslider: UISlider!@IBOutlet weak var Blueslider: UISlider!@IBOutlet weak var Alphaslider: UISlider!@IBOutlet weak var StarladyImageview: UIImageView!@IBAction func RandomColor(_ sender: UIButton) {let red = CGFloat.random(in: 0...1)let green = CGFloat.random(in: 0...1)let blue = CGFloat.random(in: 0...1)let alpha = CGFloat.random(in: 0...1)StarladyImageview.backgroundColor = UIColor(red: red, green: green, blue: blue, alpha: alpha)}@IBAction func Colorchange(_ sender: UISlider) {StarladyImageview.backgroundColor = UIColor(red: CGFloat(Redslider.value), green: CGFloat(Greenslider.value), blue: CGFloat(Blueslider.value), alpha: CGFloat(Alphaslider.value))redValueLabel.text = String(format: "%.2f", Redslider.value)greenValueLabel.text = String(format: "%.2f", Greenslider.value)blueValueLabel.text = String(format: "%.2f", Blueslider.value)}override func viewDidLoad() {super.viewDidLoad()// Do any additional setup after loading the view, typically from a nib.}}
Github