三个滑竿代表红绿蓝,修改view的颜色
import UIKit
class ViewController: UIViewController {
var redSlider : UISlider! = nil
var greenSlider : UISlider! = nil
var blueSlider : UISlider! = nil
override func viewDidLoad() {
super.viewDidLoad()
redSlider = UISlider(frame: CGRect(x: 100, y: 150, width: 200, height: 40))
self.view.addSubview(redSlider)
redSlider.minimumValue = 0;
redSlider.maximumValue = 255;
redSlider.addTarget(self, action: #selector(sliderAction(slider:)), for: .valueChanged)
greenSlider = UISlider(frame: CGRect(x: 100, y: 250, width: 200, height: 40))
self.view.addSubview(greenSlider)
greenSlider.minimumValue = 0;
greenSlider.maximumValue = 255;
greenSlider.addTarget(self, action: #selector(sliderAction(slider:)), for: .valueChanged)
blueSlider = UISlider(frame: CGRect(x: 100, y: 350, width: 200, height: 40))
self.view.addSubview(blueSlider)
blueSlider.minimumValue = 0;
blueSlider.maximumValue = 255;
blueSlider.addTarget(self, action: #selector(sliderAction(slider:)), for: .valueChanged)
redSlider.thumbTintColor = UIColor.red
blueSlider.thumbTintColor = UIColor.blue
greenSlider.thumbTintColor = UIColor.green
}
func sliderAction(slider:UISlider) {
self.view.backgroundColor = UIColor(red:CGFloat(self.redSlider.value) / 255.0, green: CGFloat(self.greenSlider.value) / 255.0, blue: CGFloat(self.blueSlider.value) / 255.0, alpha: 1) ;
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}