如何使用 NSUserdefaults 在 textview 上保存文本颜色

发布于 2024-12-07 04:02:05 字数 149 浏览 5 评论 0原文

我是iphone开发者的初学者,我的问题是如何在textview上保存textcolor。 我想在每个按钮中设置一种颜色。当我点击按钮时。按钮的颜色文本会写在文本视图上,同时也保存该功能。当我打开应用程序时,它不会丢失旧功能。那么如何解决这个问题请帮助我。

谢谢...

I am the beginner of iphone developer,my problem is how to save the textcolor on textview.
i want to taken 3buttons in each one set one color.when i tap the button.what the button had color text write on textview and at the same time save the feature also.when i open the application it does not lose the old feature.so how can solve the problem please help me.

thanks...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我的奇迹 2024-12-14 04:02:05

您可以归档任何对象并将其存储在用户默认值中。设置它:

NSData *colorData = [NSKeyedArchiver archivedDataWithRootObject:color];
[[NSUserDefaults standardUserDefaults] setObject:colorData forKey:@"color1"];

并检索它:

NSData *colorData = [[NSUserDefaults standardUserDefaults] objectForKey:@"color1"];
UIColor *color = [NSKeyedUnarchiver unarchiveObjectWithData:colorData];

You can archive any object and store it in user defaults. To set it:

NSData *colorData = [NSKeyedArchiver archivedDataWithRootObject:color];
[[NSUserDefaults standardUserDefaults] setObject:colorData forKey:@"color1"];

And to retreive it:

NSData *colorData = [[NSUserDefaults standardUserDefaults] objectForKey:@"color1"];
UIColor *color = [NSKeyedUnarchiver unarchiveObjectWithData:colorData];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文