0
votes

I have 3 RGB sliders in my settings tab that change the color of the background of that specific ViewController. I would also like it to change the color of a text label. The thing is, the text label is on a different view controller. Which means I may probably have to use NSUserDefaults. The text label is a quote on the QOTD Tab.

Problem: How do I change the color of a text label on a different ViewController and let that color be saved until changed?

import UIKit

class colorSliders: UIViewController {

@IBOutlet weak var redSlider: UISlider!
@IBOutlet weak var greenSlider: UISlider!
@IBOutlet weak var blueSlider: UISlider!

override func viewDidLoad() {
    super.viewDidLoad()


    updateBackgroundColor()
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
}

@IBAction func updateBackgroundColor() {
    let red = CGFloat(redSlider.value)
    let green = CGFloat(greenSlider.value)
    let blue = CGFloat(blueSlider.value)

    view.backgroundColor = UIColor(red: red, green: green, blue: blue, alpha: 1)
}




}

This is the code for the RGB sliders.

The ViewController with the quote on it contains:

UILabel! = quoteDisplay

If you need more information, feel free to comment what you would like to see and I will add it immediately. Thank you in advance!

1
Where is the viewController with the textLabel in relation to your color slider? does the slider push the viewController? or does the viewController push the sliders viewController?NSGangster
It is in the same Tab Bar controller as the colorSliders.swiftJ Norris

1 Answers

0
votes

NSUserDefaults is probably not a good idea for a small set of specific values. I suggest declaring a structure with static variables, one that can be shared throughout your code:

struct UserInterfaceSettings
{
    static var myColor: UIColor! = UIColor.whiteColor()
}