そのオプションがどこにあるのかわかりません。助けてください!これは本当に必要です。コードでオプションの値を使用していません。
import UIKit
class ViewController: UIViewController {
//this is the outlet for the sliders RGB values
@IBOutlet weak var redSlider: UISlider!
@IBOutlet weak var greenSlider: UISlider!
@IBOutlet weak var blueSlider: UISlider!
//this are the outlets for the labels
@IBOutlet weak var redLabelValue: UILabel!
@IBOutlet weak var greenLabelValue: UILabel!
@IBOutlet weak var blueLabelValue: UILabel!
@IBOutlet weak var hexColor: UILabel!
func changeThumbImage() {
let redThumbImage = UIImage(named: "RedThumb@3x")
redSlider.setThumbImage(redThumbImage, forState: .Normal)
let greenThumbImage = UIImage(named: "GreenThumb@3x")
greenSlider.setThumbImage(greenThumbImage, forState: .Normal)
let blueThumbImage = UIImage(named: "BlueThumb@3x")
blueSlider.setThumbImage(blueThumbImage, forState: .Normal)
}
func colorValues() {
var roundedRed = UInt32(redSlider.value)
var roundedGreen = UInt32(greenSlider.value)
var roundedBlue = Int32(blueSlider.value)
//converts the slider value to a string
redLabelValue.text = String(stringInterpolationSegment: roundedRed)
greenLabelValue.text = String(stringInterpolationSegment: roundedGreen)
blueLabelValue.text = String(stringInterpolationSegment: roundedBlue)
}
func rgbValues() {
var redValue = Int(redSlider.value)
var greenValue = Int(greenSlider.value)
var blueValue = Int(blueSlider.value)
}
//VIEW DID LOAD
override func viewDidLoad() {
super.viewDidLoad()
updateBackgroundColor()
colorValues()
changeThumbImage()
redSlider = UISlider(frame: CGRect(x: 100,y: 100,width: 200,height: 25))
func getRandomColor() -> UIColor{
let uniformRed = UInt32(redSlider.value)
let uniformGreen = UInt32(greenSlider.value)
let uniformBlue = UInt32(blueSlider.value)
var randomRed:CGFloat = CGFloat(arc4random_uniform(uniformRed))
var randomGreen:CGFloat = CGFloat(arc4random_uniform(uniformGreen))
var randomBlue:CGFloat = CGFloat(arc4random_uniform(uniformBlue))
return UIColor(red: randomRed, green: randomGreen, blue: randomBlue, alpha: 1.0)
}
//view.backgroundColor = getRandomColor()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func updateBackgroundColor() {
colorValues()
//constant to set the value of the slider to a CGFloat
let redValue = CGFloat(redSlider.value/255)
let greenValue = CGFloat(greenSlider.value/255)
let blueValue = CGFloat(blueSlider.value/255)
//set the RGBA values
view.backgroundColor = UIColor(red: redValue, green: greenValue, blue: blueValue, alpha: 1)
//get the hexadecimal value from the RGB color values
let hexValue = String(format:"%02X", Int(redSlider.value)) + String(format:"%02X", Int(greenSlider.value)) + String(format:"%02X", Int(blueSlider.value))
hexColor.text = "#\(hexValue)"
}
//get rid of status bar
override func prefersStatusBarHidden() -> Bool {
return true
}
}