开发者

How to load and save the alpha of a UIButton?

How can I save and load the UIButton's alpha values 开发者_JS百科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.


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


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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜