Themes in Cocoa apps
APTheme, APSettingTheme, APFeedbackTheme, APAppUpdateConsentTheme, APUserConsentTheme, APThemeSwift, and CrossPromoTheme are the protocols that you can use to customize the Analytics screen, App updates screen, Feedback screen, and CrossPromotion screen.
- Create a swift/Obj class in the ThemeManager and extend the protocols to provide implementations of its requirement.
Copied@interface CustomTheme : NSObject <APTheme>
@end
@implementation CustomTheme
@end
@interface CustomFeedackTheme : NSObject <APFeedbackTheme>
@end
@implementation CustomFeedackTheme
@end
@interface CustomSettingsTheme : NSObject <APSettingsTheme>
@end
@implementation CustomSettingsTheme
@end
@interface CustomUserConsentTheme : NSObject <APUserConsentTheme>
@end
@implementation CustomUserConsentTheme
@end
@interface CustomAppUpdateConsentTheme : NSObject <APAppUpdateConsentTheme>
@end
@implementation CustomAppUpdateConsentTheme
@end
Copiedclass CustomTheme : NSObject, APTheme{
}
class CustomFeedackTheme : NSObject, APFeedbackTheme{
}
class CustomSettingsTheme : NSObject, APSettingsTheme{
}
class CustomUserConsentTheme : NSObject, APAppUpdateConsentTheme{
}
class CustomAppUpdateConsentTheme : NSObject, APUserConsentTheme{
}
Show full
Show less
- You can overwrite the themes by using the set methods in Apptics class.
Copied [Apptics setTheme:[CustomTheme new]];
[Apptics setFeedbackTheme:[CustomFeedackTheme new]];
[Apptics setSettingsTheme:[CustomSettingsTheme new]];
[Apptics setUserConsentTheme:[CustomUserConsentTheme new]];
[Apptics setAppUpdateConsentTheme:[CustomAppUpdateConsentTheme new]];
CopiedApptics.setTheme(CustomTheme())
Apptics.setFeedbackTheme(CustomFeedackTheme())
Apptics.setSettingsTheme(CustomSettingsTheme())
Apptics.setUserConsentTheme(CustomUserConsentTheme())
Apptics.setAppUpdateConsentTheme(CustomAppUpdateConsentTheme())
- Return the default value for the trait in the methods that you implement. You can achieve this by extending UIColor class as given in the below sample. UIColor extension method which returns the color based on the current trait.
Copied@interface UIColor (appearance)
+(UIColor*) getColorForTraitWithDark : (UIColor*) dark andWhite : (UIColor*) white;
@end
+(UIColor*) getColorForTraitWithDark : (UIColor*) dark andWhite : (UIColor*) light{
if (@available(iOS 13.0, *)) {
return [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull traits) {
return traits.userInterfaceStyle == UIUserInterfaceStyleDark ? dark : light;
}];
} else {
return light;
}
}
Copiedextension UIColor {
public static func getAppearance(dark: UIColor,light: UIColor) -> UIColor {
if #available(iOS 13, *) {
return UIColor {(trait) -> UIColor in
if trait.userInterfaceStyle == .dark {
return dark
} else if trait.userInterfaceStyle == .light{
return light
}else{
return light
}
}
}else{
return light
}
}
}
Show full
Show less
- To customize the CrossPromotion screen just assign colors and fonts directly like below, refer APThemeSwiftManager and CrossPrmoTheme classes.
Copied[APThemeSwiftManager crosspromotheme].viewBGColor = UIColor.whiteColor;
CopiedAPThemeSwiftManager.crosspromotheme.viewBGColor = .white