This question already has answers here:
Closed 8 years ago.
Possible Duplicate:
How would I save a UIButton's properties and load with a button?
I am trying to save the values of "alpha" in 6 UIButtons in my app. How can I save the states when a button is pressed and load them when another button is pressed?
I am fairly new to this saving and loading so what would be the easiest way of doing this?
Searched everywhere and nothing seems to work...
I really don't understand what you're trying to do, but here is how you would extract the alpha component of a button's background color and save it (I haven't compiled this but this should be close):
// get the alpha value from the CGColor components from the button's backgroundColor
UIColor* color = button.backgroundColor;
const CGFloat *components = CGColorGetComponents(color.CGColor);
CGFloat alpha = components[CGColorGetNumberOfComponents(color.CGColor)-1];
Now you can use setFloat:forKey: to save the value to the NSUserDefaults:
// save alpha value (0.0=transparent to 1.0=opaque)
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setFloat:alpha forKey:@"buttonColorKey"]; // use your own key string
Use NSUserDefaults to store and load the alpha values.