IOS 如何在用户选择不同主题时刷新正在运行的应用程序(即强制视图控制器使用不同的 nib 文件重新加载)

发布于 2024-11-30 06:49:25 字数 299 浏览 0 评论 0原文

如果您的应用程序通过为其视图控制器提供多个 nib 文件来支持多个 UI 主题,那么当用户通过应用程序中的设置菜单更改主题时,您可以选择哪些选项来使正在运行的应用程序的视图控制器使用不同的视图重新加载其视图。 nib 文件?

我已经了解基础知识 - 即您可以根据存储在 NSUserDefaults 等位置的设置有条件地加载不同的 nib 文件。但之后,当用户(在应用程序中)更改主题设置时,我要如何选择才能使更改生效?

我想我可以告诉用户主题更改将在他下次启动应用程序时生效,但是实时呢?我可以强制应用程序重新加载视图,就像发生内存不足情况时那样吗?

If your app supports multiple UI themes by having multiple nib files for it's view controllers, then when the user changes the theme through a settings menu in the app, what are your options for causing the running app's view controllers to reload their views with a different nib file?

I'm already aware of the basics - i.e. that you can load a different nib file conditionally based on a setting stored somewhere like NSUserDefaults. But after that, at the moment the user (in the app) changes the theme setting, what are my choices for having the change take effect?

I imagine I could tell the user that the theme change will take effect the next time he starts the app, but what about in real-time? Can I force the app to reload views similar to the way it does when a low memory condition occurs?

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

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

发布评论

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

评论(1

ζ澈沫 2024-12-07 06:49:25

我认为您可能以错误的方式处理这个问题。

如果您只是根据主题更改颜色和图像,我会考虑创建一个 xib 并更改代码中的颜色和图像。

多个 xib 的问题是,当真正唯一的变量可能是属性时,您会增加需要维护的内容。

更改属性要简单得多,您还可以引入一个新类来管理主题,

例如

// psuedo class/code
Theme *theme = [[Theme alloc] initWithStyle:ThemeWarm];

self.view.backgroundColor = theme.backgroundColor;
self.view.logo            = theme.logo;

I think you may be approaching this in the wrong way.

If you are simply changing colours and images depending on the theme I would consider creating one xib and changing the colours and images in code.

The problem with multiple xibs is you increase the amount of things you need to maintain when really the only variables are likely to be properties.

Changing properties is much simpler and you could also introduce a new class to manage themes

e.g.

// psuedo class/code
Theme *theme = [[Theme alloc] initWithStyle:ThemeWarm];

self.view.backgroundColor = theme.backgroundColor;
self.view.logo            = theme.logo;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文