Creating a night theme for my application

I am new to iOS development and wondered how to add a night theme similar to tweetbot 3 and understandable. From my research, I really could not find anything in my iOS apps.

Would I remake the app in another theme-specific storyboard?

thanks.

+4
source share
1 answer

To add to what others have said, there is a WWDC video on the subject of your code. I took this a step further and created an easy basis for the theses that I use in several of my applications. The bottom line is as follows.

, , .. ( , ), , . , "", (, , , , - , sake - WrappedButton).

uml, ...

Theme UML Diagram

.

@protocol Theme <NSObject>

- (void)themeHeadingLabel:(UILabel *)headingLabel;
- (void)themeBodyLabel:(UILabel *)bodyLabel;

- (void)themeNavigationButton:(UIButton *)navigationButton;
- (void)themeActionButton:(UIButton *)actionButton;

@end

, , , .. ( "" ) 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 logic
}

@end

, , , factory.

UILabel* headingLabel = [[UILabel alloc] init];
headingLabel.text = @"My Heading";

[[ThemeManager theme] themeHeadingLabel:myHeading];

// use the label

factory, ..

- (UILabel *)buildLabelWith:(NSString *)text
{
    UILabel* headingLabel = [[UILabel alloc] init];
    headingLabel.text = text;

    [[ThemeManager theme] themeHeadingLabel:myHeading];

    return headingLabel;
}

, . - , .

+16

All Articles