pixelbitlabs
pixelbitlabs

Reputation: 1934

How to load and save the alpha of a UIButton?

How can I save and load the UIButton's alpha values in my iPhone app? I want to do this the easiest way possible. I have tried using various methods, but none have worked for me so far.

Upvotes: 0

Views: 275

Answers (2)

chown
chown

Reputation: 52738

Try this:

CGFloat alpha = myButton.layer.opacity;

You might need to #import <QuartzCore/QuartzCore.h>.


Edit (From this SO Question):

Then, you can simply store it in NSUserDefaults:

[[NSUserDefaults standardUserDefaults] setObject:myButton.backgroundColor forKey:@"buttonColor"];
[[NSUserDefaults standardUserDefaults] synchronize];  // Thanks @Shah for reminding us about this!

Then retrieve it like such:

myButton.backgroundColor = [[NSUserDefaults standardUserDefaults] objectForKey:@"buttonColor"];

And when you're done with it:

[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"buttonColor"];

NSUserDefaults Class Reference

Upvotes: 2

Faizan S.
Faizan S.

Reputation: 8644

You might want to have a look at the NSUserDefaults.

// Setting a value
[[NSUserDefaults standardUserDefaults] setFloat:VALUE forKey:KEY];
[[NSUserDefaults standardUserDefaults] synchronize]; // This line is required to persist all changes make to the User Defraults

// Getting a value
[[NSUserDefaults standardUserDefaylt] floatForKey:KEY];

Upvotes: 0

Related Questions