iphone - 如何加载和保存 UIButton 的 alpha?

标签 iphone objective-c ios xcode uibutton

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

最佳答案

试试这个:

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

关于iphone - 如何加载和保存 UIButton 的 alpha?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7374040/

相关文章:

ios - 格式化体积和质量单位

ios - 如何像cashapelayer一样设置UIbutton的点

iphone - 长按并单击按钮

ios - UITableViewCell 的 textLabel 中的两行,新行仅由文本中的换行符确定

ios - 使用按钮和文本字段/ View (iPhone) 打开电话(调用)

iphone - 搜索栏的 iOS 色调文本字段背景

iphone - 在 opengl 中平滑不起作用

iphone - Quick Look 和 UIWebView 支持的文件类型

iOS:是否可以为侧载开发应用程序推送更新?

iphone - presentModalViewController如何与嵌套的UITabBarController和UINavigationController交互