通過設(shè)置UI單例類控制APP內(nèi)的樣式變化.樣式的屬性為只讀.
#import <Foundation/Foundation.h>
@interface AlivcUIConfig : NSObject
+ (instancetype)shared;
/**
背景顏色
*/
@property (strong, nonatomic, readonly) UIColor *kAVCBackgroundColor;
/**
系統(tǒng)色
*/
@property (strong, nonatomic, readonly) UIColor *kAVCThemeColor;
@end
#import "AlivcUIConfig.h"
#import "UIColor+AlivcHelper.h"
static AlivcUIConfig *sharedIns = nil;
@implementation AlivcUIConfig
+ (instancetype)shared{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
if (!sharedIns) {
sharedIns = [[AlivcUIConfig alloc]_init];
}
});
return sharedIns;
}
- (instancetype)init{
@throw [NSException exceptionWithName:@"AlivcUIConfig init error" reason:@"'shared' to get instance." userInfo:nil];
return [super init];
}
- (instancetype)_init {
self = [super init];
if (self) {
_kAVCBackgroundColor = [UIColor colorWithHexString:@"1e222d"];
_kAVCThemeColor = [UIColor colorWithHexString:@"00c1de"];
}
return self;
}
@end
使用方式
self.view.backgroundColor = [AlivcUIConfig shared].kAVCBackgroundColor;