作業10#13 彼得潘的影子 — 調色大師
Published in
Jan 1, 2022
做了一個極簡易版的調色
祝大家新年快樂!
import UIKitclass ViewController: UIViewController {
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var redSlider: UISlider!
@IBOutlet weak var greenSlider: UISlider!
@IBOutlet weak var blueSlider: UISlider!
@IBOutlet weak var alphaSlider: UISlider!override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}@IBAction func changeColor(_ sender: Any) {
imageView.backgroundColor = UIColor(red: CGFloat(redSlider.value), green: CGFloat(greenSlider.value), blue: CGFloat(blueSlider.value), alpha: CGFloat(alphaSlider.value))
}
@IBAction func randomColor(_ sender: Any) {
redSlider.value = Float.random(in: 0...1)
greenSlider.value = Float.random(in: 0...1)
blueSlider.value = Float.random(in: 0...1)
imageView.backgroundColor = UIColor(red: CGFloat(redSlider.value), green: CGFloat(greenSlider.value), blue: CGFloat(blueSlider.value), alpha: CGFloat(alphaSlider.value))
}
}