我回来了之笔记3

回来了 ,还是用这个吧

暗黑模式

#define iSDark ([UIApplication sharedApplication].delegate.window.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) //是否是暗黑模式

    if (@available(iOS 13.0, *)) {
        UIColor *divideLineDyColor = [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull trainCollection) {
            if ([trainCollection userInterfaceStyle] == UIUserInterfaceStyleLight) {
                return [UIColor colorWithRed:rgb2 green:rgb2 blue:rgb2 alpha:1.0];
            } else {
                CGFloat lineDarkRgb = 100 / 255.0;
                return [UIColor colorWithRed:lineDarkRgb green:lineDarkRgb blue:lineDarkRgb alpha:1.0];
            }
        }];
        _divideLine.backgroundColor = divideLineDyColor;
    } else {
        _divideLine.backgroundColor = [UIColor colorWithRed:rgb2 green:rgb2 blue:rgb2 alpha:1.0];
    }
- (void)configCurrentThemeWithThemeName:(NSString *)themeName {
    if (!themeName || [themeName isEqualToString:@""] || [themeName isKindOfClass:[NSNull class]]) {
        return;
    }
//    NSString *jsonFileName = [_themeListDic objectForKey:themeName];
    NSString *jsonFileName = [_themeListDic valueForKey:themeName];
    if (!jsonFileName || [jsonFileName isEqualToString:@""] || [jsonFileName isKindOfClass:[NSNull class]]) {
        [[NSUserDefaults standardUserDefaults] setObject:_themeName forKey:@"ThemeName"];
        return;
    }
     if (@available(iOS 12.0, *)) {
           BOOL isDark = ([UIApplication sharedApplication].delegate.window.traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark);
         if (isDark && ([_themeName isEqualToString:@"TerryKou"] || [_themeName isEqualToString:@"TPP"])) {
               jsonFileName = [NSString stringWithFormat:@"%@_dark",jsonFileName];
           }
         
         if (isDark) {
             _keyboardThemeFileName = @"keyboard_dark";
         }
       } else {
           
       }
       NSString *fileName = [NSString stringWithFormat:@"%@.json",jsonFileName];
       NSData *data = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:fileName ofType:nil]];
    NSData *keyboardData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@.json", _keyboardThemeFileName] ofType:nil]];
    if (data == nil || keyboardData == nil) {
        return;
    }
    NSDictionary *keyboardDic = [NSJSONSerialization JSONObjectWithData:keyboardData options:NSJSONReadingAllowFragments error:nil];
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];

    ThemePropertys *keyboardThemePropertys = [ThemePropertys yy_modelWithDictionary:keyboardDic];
    ThemePropertys *themePropertys = [ThemePropertys yy_modelWithDictionary:dic];
    [keyboardThemePropertys setKeyboardPropertys];
    [themePropertys setPropertys];
}

定义一个颜色类

- (void)setPropertys{
    TCOLOR_THEME_navigation = _TCOLOR_THEME_navigation;
}

把json文件通过YYModel赋值给ThemePropertys模型, 通过模型类 方法setPropertys 赋值给外部(extern)全局变量 TCOLOR_THEME_navigation

——————————————————————————————————

Theme.h.m
定义外部全局变量
extern NSString* TCOLOR_THEME_version;
Theme.m
NSString* TCOLOR_THEME_version;
定义全局变量NSString* TCOLOR_version=@"";

用外部全局变量给全局变量赋值
+(void)setThemeComponentStyle{
TCOLOR_version = TCOLOR_THEME_version;
}

ThemeProperty 是模型类
属性@property (nonatomic, copy, readwrite) NSString *TCOLOR_THEME_version;

  • (void)setPropertys{
    全局变量TCOLOR_THEME_version = 属性_TCOLOR_THEME_version;
    }

Json: “TCOLOR_THEME_version” : “efefef”,

代码中
[Btncancle setTitleColor:[CommonMethods colorWithHexColorString:TCOLOR_version] forState:UIControlStateNormal];

TCOLOR_THEME_version; = 13123

1 Theme.m中的方法调用 , 把json 转化为模型

  • (void)configCurrentThemeWithThemeName:(NSString *)themeName {}

模型中属性得到值 调用- (void)setPropertys方法 赋值给 外部全局变量TCOLOR_THEME_version

再调用Theme.m+(void)setThemeComponentStyle{ 赋值给全局变量TCOLOR_version

—————————————————————————————————

CommonMethods

+(UIColor *)colorWithHexColorString:(NSString *)hexColorString{
    if ([hexColorString length]<6)
    {
        return [ UIColor blackColor];
    }
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    NSString *tempString = [hexColorString lowercaseString];
    if ([tempString hasPrefix:@"0x"]) { //检查开头是0x
        tempString = [tempString substringFromIndex:2];
    }
    else if ([tempString hasPrefix:@"#"]){   //检查开头是#
        tempString = [tempString substringFromIndex:1];
    }
    if ([tempString length] != 6) {
        return [UIColor blackColor];
    }
    //分解三种颜色的值
    NSRange range;
    range.location=0;
    range.length=2;
    NSString *rString = [tempString substringWithRange:range];
    range.location=2;
    NSString *gString = [tempString substringWithRange:range];
    range.location=4;
    NSString *bString = [tempString substringWithRange:range];
    //取三种颜色值
    unsigned int red,green,blue;
    [[NSScanner scannerWithString:rString] scanHexInt:&red];
    [[NSScanner scannerWithString:gString] scanHexInt:&green];
    [[NSScanner scannerWithString:bString] scanHexInt:&blue];
    [pool drain];
    return [UIColor colorWithRed:((float)red/255.0f)
                            green:((float)green/255.0f)
                             blue:((float)blue/255.0f)
                            alpha:100.0f];
}

——————————————————————————————————
stackView

@IBAction func addStar(_ sender: Any) {
        let starImgVw:UIImageView = UIImageView(image: UIImage(named: "star"))
        starImgVw.contentMode = .scaleAspectFit
        self.horizontalStackView.addArrangedSubview(starImgVw)
        UIView.animate(withDuration: 0.25, animations: {
            self.horizontalStackView.layoutIfNeeded()
        })
    }
    

    @IBAction func removeStar(_ sender: Any) {
        let star:UIView? = self.horizontalStackView.arrangedSubviews.last
        if let aStar = star
        {
            self.horizontalStackView.removeArrangedSubview(aStar)
            aStar.removeFromSuperview()
            UIView.animate(withDuration: 0.25, animations: {
                self.horizontalStackView.layoutIfNeeded()
            })
        }
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值