iOS 统一设置UI公共参数的思路

2019-04-08  本文已影响0人  别闹_53c1

通过设置UI单例类控制APP内的样式变化.样式的属性为只读.

#import <Foundation/Foundation.h>

@interface AlivcUIConfig : NSObject

+ (instancetype)shared;

/**
 背景颜色
 */
@property (strong, nonatomic, readonly) UIColor *kAVCBackgroundColor;

/**
 系统色
 */
@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;

上一篇 下一篇

猜你喜欢

热点阅读