为我的应用程序创build一个夜晚主题

我是iOS开发新手,想知道如何添加一个类似于tweetbot 3的夜晚主题并清除。 从我的研究,我还没有真正能够find主题iOS应用程序上的任何东西。

我会在另一个主题的故事板中重新制作应用程序吗?

谢谢。

为了增加别人的话,有一个关于主题代码的WWDCvideo。 我已经采取了更进一步的步骤,并创build了一个轻量级的主题框架,我使用了几个应用程序。 要点如下。

每次你创build一个标签,button等等(或者当他们将要出现在屏幕上时,如果你使用接口生成器),你将它们传递给一个Theme实例来设置它们的外观和感觉。 如果几个UI组件一起工作,则使用Facadedevise模式将它们合并为一个对象(例如,如果您有一个在特定位置具有客户封装器,标签和图像的button,则将它们包装到一个单一的类叫 – 例如为了 – WrappedButton)。

我有时觉得用uml来沟通更容易,所以…

主题UML图

主题协议可能看起来像这样。

@protocol Theme <NSObject> - (void)themeHeadingLabel:(UILabel *)headingLabel; - (void)themeBodyLabel:(UILabel *)bodyLabel; - (void)themeNavigationButton:(UIButton *)navigationButton; - (void)themeActionButton:(UIButton *)actionButton; @end 

顺便说一下,我通常会把代码放在那里,以允许button,标签等响应iOS7中的文本大小更改(从“设置”应用程序)。 所以也可以有这样的方法,

 - (void)respondToTextSizeChangeForHeadingLabel:(UILabel *)headingLabel; - (void)respondToTextSizeChangeForBodyLabel:(UILabel *)bodyLabel; // and do the same for buttons 

那么,当然,你将有一个或多个该协议的实现 。 这是你的主题将生活的地方。 这里有一些可能看起来像什么的片段。

 #import "Theme.h" @interface LightTheme : NSObject <Theme> @end @implementation LightTheme - (void)themeHeadingLabel:(UILabel *)headingLabel { headingLabel.backgroundColor = [UIColor lightTextColor]; headingLabel.textColor = [UIColor darkTextColor]; headingLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline]; } // the rest of your theming @end 

而且你可以有一个黑暗的主题,其实现看起来像这样。

 @implementation DarkTheme - (void)themeHeadingLabel:(UILabel *)headingLabel { headingLabel.backgroundColor = [UIColor darkGrayColor]; headingLabel.textColor = [UIColor lightTextColor]; headingLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline]; } // the rest of your theming @end 

我总是把它包装在一个ThemeManager中,以帮助我跟踪主题 。 这可以看起来像这样。

 #import "Theme.h" @interface ThemeManager : NSObject + (id <Theme>)theme; @end #import "LightTheme.h" #import "DarkTheme.h" @implementation ThemeManager + (id <Theme>)theme { // here you'd return either your light or dark theme, depending on your program's logic } @end 

现在,把它们联系在一起,你可以直接或者在工厂使用。

 UILabel* headingLabel = [[UILabel alloc] init]; headingLabel.text = @"My Heading"; [[ThemeManager theme] themeHeadingLabel:myHeading]; // use the label 

或者作为一个工厂,实现将看起来像这样

 - (UILabel *)buildLabelWith:(NSString *)text { UILabel* headingLabel = [[UILabel alloc] init]; headingLabel.text = text; [[ThemeManager theme] themeHeadingLabel:myHeading]; return headingLabel; } 

希望有所帮助。 如果您有任何问题,请告诉我。