保存 UIButton 状态并使用 NSUserDefaults 加载
我想知道如何检测按钮是否隐藏,以及对其应用了多少 Alpha。然后,当调用 viewDidLoad 时,可以应用这些值以使按钮与应用程序关闭时保持的状态相同。
我该如何编码?
谢谢,
詹姆斯
I was wondering how to detect whether the button was hidden or not, and how much alpha was applied to it. Then, when viewDidLoad is called, these values can be applied to make the buttons the same state they were left in when the application closed.
How can I code this?
Thanks,
James
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果,正如您的标题所示,您想使用
NSUserDefaults
,那么您可以这样设置它们:如果您想对多个按钮执行此操作,那么您可以使用
tag
s 在默认值中区分它们:If, as your title suggests, you want to use
NSUserDefaults
, then you can set them like this:If you want to do this for multiple buttons, then you can use
tag
s to differentiate between them in the defaults:要检查按钮状态,请检查此帖子: Xcode:检查 UIButton是隐藏的,使用 NSUserDefaults
关于Alpha,尝试求一下返回值:self.button.alpha;
您可以更新 SQLite 数据库中按钮和 Alpha 按钮的状态(值)。在 viewDidLoad 方法中,从数据库回调值并立即应用它们。关于如何做到这一点,请在网上查看更多信息,您就会到达那里,因为互联网上充满了有关该主题的教程。嗯,这就是我要做的,SQLite 实际上非常有用;但也许还有其他方法。
To check out the button state, check this post: Xcode: Check if UIButton is hidden, using NSUserDefaults
Regarding the Alpha, try to ask for the return value of: self.button.alpha;
you can update the state (value) of the button and the Alpha button in an SQLite database. In the viewDidLoad method, call back the values from the database and apply them immediately. On how to do this, check out some more info on the web and you'll get there because the internet is filled with tutorials on the topic. Well, that's what I would do, SQLite is really useful actually; but perhaps there are other ways as well.