如何加载和保存UIButton的alpha?

时间:2011-09-10 19:22:52

标签: iphone objective-c ios xcode uibutton

如何在iPhone应用程序中保存和加载UIButton的alpha值?我想以最简单的方式做到这一点。我尝试过使用各种方法,但迄今为止没有一种方法适用于我。

2 个答案:

答案 0 :(得分:2)

试试这个:

CGFloat alpha = myButton.layer.opacity;

您可能需要#import <QuartzCore/QuartzCore.h>


编辑(来自此SO Question):

然后,您只需将其存储在NSUserDefaults

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

然后像这样检索它:

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

当你完成它时:

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

NSUserDefaults Class Reference

答案 1 :(得分:0)

您可能需要查看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];