Commit d8ad9052 cgx

完成系统设置主题模式切换

1 个父辈 d03ad2c0
正在显示 22 个修改的文件 包含 283 行增加30 行删除
......@@ -42,6 +42,7 @@
D0930F122801124E006B497A /* BaseNaviController.m in Sources */ = {isa = PBXBuildFile; fileRef = D0930F112801124E006B497A /* BaseNaviController.m */; };
D0930F1A2801874B006B497A /* UIViewController+Swizzling.m in Sources */ = {isa = PBXBuildFile; fileRef = D0930F152801874B006B497A /* UIViewController+Swizzling.m */; };
D0930F1B2801874B006B497A /* UINavigationController+Pop.m in Sources */ = {isa = PBXBuildFile; fileRef = D0930F182801874B006B497A /* UINavigationController+Pop.m */; };
D09D0E96280D3FE9008DEDAB /* NSDate+Extras.m in Sources */ = {isa = PBXBuildFile; fileRef = D09D0E95280D3FE9008DEDAB /* NSDate+Extras.m */; };
D0B5ECA627F2D9DE003EDFE3 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = D0B5ECA527F2D9DE003EDFE3 /* AppDelegate.m */; };
D0B5ECAF27F2D9DE003EDFE3 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = D0B5ECAD27F2D9DE003EDFE3 /* Main.storyboard */; };
D0B5ECB127F2D9E0003EDFE3 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D0B5ECB027F2D9E0003EDFE3 /* Assets.xcassets */; };
......@@ -151,6 +152,8 @@
D0930F172801874B006B497A /* UIViewController+Swizzling.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIViewController+Swizzling.h"; sourceTree = "<group>"; };
D0930F182801874B006B497A /* UINavigationController+Pop.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UINavigationController+Pop.m"; sourceTree = "<group>"; };
D0930F192801874B006B497A /* NaviBarHandlerProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NaviBarHandlerProtocol.h; sourceTree = "<group>"; };
D09D0E94280D3FE9008DEDAB /* NSDate+Extras.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSDate+Extras.h"; sourceTree = "<group>"; };
D09D0E95280D3FE9008DEDAB /* NSDate+Extras.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSDate+Extras.m"; sourceTree = "<group>"; };
D0B5ECA127F2D9DE003EDFE3 /* DreamSleepDev.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DreamSleepDev.app; sourceTree = BUILT_PRODUCTS_DIR; };
D0B5ECA427F2D9DE003EDFE3 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
D0B5ECA527F2D9DE003EDFE3 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
......@@ -299,6 +302,8 @@
D0506B0B280503A800229278 /* UIButton+Extras.m */,
D091BBB92809079600487A50 /* NSString+Extras.h */,
D091BBBA2809079600487A50 /* NSString+Extras.m */,
D09D0E94280D3FE9008DEDAB /* NSDate+Extras.h */,
D09D0E95280D3FE9008DEDAB /* NSDate+Extras.m */,
);
path = Category;
sourceTree = "<group>";
......@@ -371,15 +376,12 @@
isa = PBXGroup;
children = (
D0CE3D80280A532D00D8B02D /* UserLogin */,
D09D0E97280D4EEA008DEDAB /* SystemSet */,
D04B3DBC27F6F8090022F8DF /* Profile.storyboard */,
D04B3DBE27F6F82D0022F8DF /* ProfileController.h */,
D04B3DBF27F6F82D0022F8DF /* ProfileController.m */,
D0E660032807D02C006562F2 /* UserRequestModel.h */,
D0E660042807D02C006562F2 /* UserRequestModel.m */,
D0E6600628080F97006562F2 /* SystemSetController.h */,
D0E6600728080F97006562F2 /* SystemSetController.m */,
D0F82284280C44D10039F586 /* SetTableView.h */,
D0F82285280C44D10039F586 /* SetTableView.m */,
);
path = Profile;
sourceTree = "<group>";
......@@ -405,6 +407,17 @@
path = DSNavigationTools;
sourceTree = "<group>";
};
D09D0E97280D4EEA008DEDAB /* SystemSet */ = {
isa = PBXGroup;
children = (
D0F82284280C44D10039F586 /* SetTableView.h */,
D0F82285280C44D10039F586 /* SetTableView.m */,
D0E6600628080F97006562F2 /* SystemSetController.h */,
D0E6600728080F97006562F2 /* SystemSetController.m */,
);
path = SystemSet;
sourceTree = "<group>";
};
D0B5EC9827F2D9DE003EDFE3 = {
isa = PBXGroup;
children = (
......@@ -768,6 +781,7 @@
D0930F1B2801874B006B497A /* UINavigationController+Pop.m in Sources */,
D0506B1528051ED400229278 /* SafeSleepModel.m in Sources */,
D01814D527FFCCFA00583D4E /* HomeTableView.m in Sources */,
D09D0E96280D3FE9008DEDAB /* NSDate+Extras.m in Sources */,
D0878F4C280BEFF9005F1B7F /* UILabel+YBAttributeTextTapAction.m in Sources */,
D0F80907280431100097899F /* UILabel+Extras.m in Sources */,
D04B3DAC27F6EEB50022F8DF /* DSTabBarController.m in Sources */,
......
......@@ -61,6 +61,15 @@
}
}
#pragma mark - 处理用户打开自动切换主题按钮,根据设定好的时间段进行主题切换
if (kGetUserDefaultsBOOL(ThemeAutoSwitch)) {
if ([NSDate judgeTimeWithStartTime:StartTime1 expireTime:ExpireTime1] || [NSDate judgeTimeWithStartTime:StartTime2 expireTime:ExpireTime2]) {
self.dk_manager.themeVersion = DKThemeVersionNight;
} else {
self.dk_manager.themeVersion = DKThemeVersionNormal;
}
}
#pragma mark - 重返系统事件
[self swiz_viewWillAppear:animated];
}
......
//
// NSDate+Extras.h
// DreamSleep
//
// Created by peter on 2022/4/18.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface NSDate (Extras)
/// 根据起始时间段判断是否是白天还是黑夜
/// @param startStr @"08:00:00"
/// @param expireStr @"12:00:00"
+ (BOOL)judgeTimeWithStartTime:(NSString *)startStr expireTime:(NSString *)expireStr;
@end
NS_ASSUME_NONNULL_END
//
// NSDate+Extras.m
// DreamSleep
//
// Created by peter on 2022/4/18.
//
#import "NSDate+Extras.h"
@implementation NSDate (Extras)
+ (BOOL)judgeTimeWithStartTime:(NSString *)startStr expireTime:(NSString *)expireStr
{
// 获取当前时间
NSDate *today = [NSDate date];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
// 时间格式,建议大写 HH 24小时制;hh 12小时制
[dateFormat setDateFormat:@"HH:mm:ss"];
// 将日期转换成字符串
NSString * todayStr = [dateFormat stringFromDate:today];
// 转换成NSDate类型。日期置为方法默认日期
today = [dateFormat dateFromString:todayStr];
// 格式,eg:"5:30:00"
NSDate *start = [dateFormat dateFromString:startStr];
NSDate *expire = [dateFormat dateFromString:expireStr];
if ([today compare:start] == NSOrderedDescending && [today compare:expire] == NSOrderedAscending) {
return YES;
}
return NO;
}
@end
......@@ -21,6 +21,8 @@ NS_ASSUME_NONNULL_BEGIN
+ (UILabel *)labWithTextColor:(UIColor *)textColor font:(UIFont *)font;
+ (UILabel *)labWithText:(NSString *)text textColor:(UIColor *)textColor font:(UIFont *)font;
+ (UILabel *)labWithText:(NSString *)text font:(UIFont *)font fit:(BOOL)fit;
@end
NS_ASSUME_NONNULL_END
......@@ -46,4 +46,12 @@
return lab;
}
+ (UILabel *)labWithText:(NSString *)text font:(UIFont *)font fit:(BOOL)fit {
UILabel *lab = [UILabel new];
lab.text = text;
lab.font = font;
if (fit) { [lab sizeToFit]; }
return lab;
}
@end
......@@ -15,6 +15,8 @@ NS_ASSUME_NONNULL_BEGIN
@property CGFloat x;
@property CGFloat y;
@property CGPoint origin;
@property CGFloat centerX;
@property CGFloat centerY;
/**
根据view获取UIViewController(该view必须完成初始化)
......
......@@ -53,6 +53,32 @@
return self.frame.origin;
}
- (void)setOrigin:(CGPoint)origin {
CGRect rect = self.frame;
rect.origin = origin;
self.frame = rect;
}
- (CGFloat)centerX {
return self.center.x;
}
- (void)setCenterX:(CGFloat)centerX {
CGPoint center = self.center;
center.x = centerX;
self.center = center;
}
- (CGFloat)centerY {
return self.center.y;
}
- (void)setCenterY:(CGFloat)centerY {
CGPoint center = self.center;
center.y = centerY;
self.center = center;
}
- (UIViewController *)ds_viewController {
for (UIView* next = [self superview]; next; next = next.superview) {
UIResponder *nextResponder = [next nextResponder];
......
......@@ -38,12 +38,10 @@
titleColor = ColorFromHex(0x333333);
bgColor = DSWhite;
barTintColor = DSWhite;
// naviBar.barStyle = UIBarStyleDefault;
} else if (style == NaviStyleDark) {
titleColor = DSWhite;
bgColor = DarkColor;
barTintColor = DarkColor;
// naviBar.barStyle = UIBarStyleBlack;
}
// 设置导航栏title颜色、导航栏背景色、隐藏分割线
......@@ -91,6 +89,11 @@
- (UIStatusBarStyle)preferredStatusBarStyle {
// 白天和黑夜2种模式
UIStatusBarStyle barStyle = [self.dk_manager.themeVersion isEqualToString:DKThemeVersionNormal] ? UIStatusBarStyleDefault : UIStatusBarStyleLightContent;
// 处理我的页面状态栏
if (kGetUserDefaultsBOOL(ThemeAutoSwitch)) {
barStyle = ([NSDate judgeTimeWithStartTime:StartTime1 expireTime:ExpireTime1] || [NSDate judgeTimeWithStartTime:StartTime2 expireTime:ExpireTime2]) ? UIStatusBarStyleLightContent : UIStatusBarStyleDefault;
}
// 默认风格模式(控制器重写navigationBarStyle方法)
UIViewController* topVC = self.topViewController;
if ([topVC respondsToSelector:@selector(navigationBarStyle)]) {
......
......@@ -24,14 +24,14 @@
self.tmpDatas = @[@"注册登录信息", @"意见反馈", @"系统设置", @"邀请好友", @"关于我们", @"前往小程序", @"关注公众号", @"添加客服微信", @"失眠的认知行为疗法"];
}
#pragma mark - 导航栏默认模式
//- (NaviStyle)navigationBarStyle {
// return NaviStyleDefault;
//}
#pragma mark - 导航栏日间、黑夜模式
- (NaviStyle)navigationBarStyle {
// 我的界面需要对用户是否打开自动切换进行处理
if (kGetUserDefaultsBOOL(ThemeAutoSwitch)) {
return ([NSDate judgeTimeWithStartTime:StartTime1 expireTime:ExpireTime1] || [NSDate judgeTimeWithStartTime:StartTime2 expireTime:ExpireTime2]) ? NaviStyleDark : NaviStyleLight;
} else {
return [self.dk_manager.themeVersion isEqualToString:DKThemeVersionNormal] ? NaviStyleLight : NaviStyleDark;
}
}
#pragma mark - Table view data source
......
......@@ -45,7 +45,7 @@
self.dk_backgroundColorPicker = DKColorPickerWithColors(DSWhite, ColorFromHex(0x1F263F), DSWhite);
self.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"moreIcon"]];
self.titleLab = [UILabel dkLabWithFont:BoldFont(15.0)];
self.titleLab = [UILabel dkLabWithFont:SysFont(15.0)];
[self addSubview:self.titleLab];
self.detailLab = [UILabel labWithFont:SysFont(14.0)];
......@@ -82,6 +82,8 @@
@interface SetTableView () <UITableViewDelegate>
@property (nonatomic, strong) DSDataSource *setDataSource;
@property (nonatomic, strong) NSArray *dataArr;
@property (nonatomic, strong) UIView *footView;
@property (nonatomic, strong) UIImageView *slideView;
@end
@implementation SetTableView
......@@ -95,6 +97,7 @@
self.dk_backgroundColorPicker = DKColorPickerWithColors(DSWhite, ColorFromHex(0x1F263F), DSWhite);
self.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.setDataSource addDataArray:self.dataArr];
self.tableFooterView = self.footView;
}
return self;
}
......@@ -113,6 +116,115 @@
return _setDataSource;
}
- (UIView *)footView {
if (!_footView) {
_footView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.width, self.height - 200)];
UILabel *titleLab = [UILabel dkLabWithFont:SysFont(15.0)];
titleLab.text = @"主题模式";
[titleLab sizeToFit];
[_footView addSubview:titleLab];
UIView *longView = [UIView new];
[longView cornerRadius:10];
longView.dk_backgroundColorPicker = DKColorPickerWithColors(BGColor, DarkColor, DSWhite);
[_footView addSubview:longView];
CGFloat leftRightSpace = 24;
CGFloat btnH = 20;
CGFloat btnW = (self.width - 2*leftRightSpace)/3.0;
for (int i = 0; i < 3; i++) {
UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(i*btnW, 0, btnW, btnH)];
btn.tag = i;
[btn addTarget:self action:@selector(switchThemeAction:) forControlEvents:UIControlEventTouchUpInside];
[longView addSubview:btn];
}
_slideView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"slideIcon"]];
[_footView addSubview:_slideView];
[titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_footView).offset(15);
make.top.equalTo(_footView);
}];
[longView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_footView).offset(leftRightSpace);
make.top.equalTo(titleLab.mas_bottom).offset(24);
make.right.equalTo(_footView).offset(-leftRightSpace);
make.height.equalTo(@(btnH));
}];
[_slideView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(longView);
make.width.equalTo(@50);
make.height.equalTo(@34);
// slideView初始化位置
if (kGetUserDefaultsBOOL(ThemeAutoSwitch)) { // 自动切换状态
make.centerX.equalTo(_footView);
} else {
if ([self.dk_manager.themeVersion isEqualToString:DKThemeVersionNormal]) {
make.left.equalTo(_footView).offset(19);
} else {
make.right.equalTo(_footView).offset(-19);
}
}
}];
NSArray *themes = @[@"日间模式", @"自动切换", @"夜间模式"];
for (int i = 0; i < 3; i++) {
UILabel *lab = [UILabel labWithText:themes[i] font:SysFont(14.0) fit:YES];
lab.dk_textColorPicker = DKColorPickerWithColors(SubTitleColor, DSWhite, DSWhite);
[_footView addSubview:lab];
[lab mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(longView.mas_bottom).offset(8);
}];
if (i == 0) {
[lab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_footView).offset(8);
make.bottom.equalTo(_footView).offset(-19);
}];
} else if (i == 1) {
[lab mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(_footView);
}];
} else if (i == 2) {
[lab mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(_footView).offset(-8);
}];
}
}
}
return _footView;
}
- (void)switchThemeAction:(UIButton *)sender {
WS(weakSelf);
if (sender.tag == 1) { // 自动切换
[UIView animateWithDuration:.3 animations:^{
weakSelf.slideView.centerX = self.footView.centerX;
}];
// 处理自动切换逻辑
if ([NSDate judgeTimeWithStartTime:StartTime1 expireTime:ExpireTime1] || [NSDate judgeTimeWithStartTime:StartTime2 expireTime:ExpireTime2]) {
self.dk_manager.themeVersion = DKThemeVersionNight;
} else {
self.dk_manager.themeVersion = DKThemeVersionNormal;
}
// 保存自动切换状态
kSetUserDefaultsBOOL(YES, ThemeAutoSwitch);
kUserDefaultsSynchronize;
} else {
CGFloat x = sender.tag == 0 ? 19 : self.footView.width - self.slideView.width - 19;
[UIView animateWithDuration:.3 animations:^{
weakSelf.slideView.x = x;
}];
self.dk_manager.themeVersion = sender.tag == 0 ? DKThemeVersionNormal : DKThemeVersionNight;
kSetUserDefaultsBOOL(NO, ThemeAutoSwitch);
kUserDefaultsSynchronize;
}
}
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 50;
......@@ -120,8 +232,10 @@
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) { // 应用版本升级
// 跳转到AppStore
[DSProgressHUD showToast:@"暂无新版本"];
NSURL *url = [NSURL URLWithString:@"itms-apps://itunes.apple.com/app/id1609336070"];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
}
} else if (indexPath.row == 3) { // 清除缓存
[DSProgressHUD showToast:@"清除成功"];
SetModel *m = self.dataArr[indexPath.row];
......
......@@ -22,22 +22,6 @@
self.view.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
[self.view addSubview:self.sTabView];
UIButton *darkBtn = [[UIButton alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(self.sTabView.frame), 100, 40)];
[darkBtn setTitle:@"黑夜模式" forState:UIControlStateNormal];
[darkBtn debugViewShowBorder];
[darkBtn setTitleColor:DSRed forState:UIControlStateNormal];
[darkBtn addTarget:self action:@selector(darkBtnAction) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:darkBtn];
}
- (void)darkBtnAction {
// 模拟切换黑夜模式
if ([self.dk_manager.themeVersion isEqualToString:DKThemeVersionNight]) {
self.dk_manager.themeVersion = DKThemeVersionNormal;
} else {
self.dk_manager.themeVersion = DKThemeVersionNight;
}
}
#pragma mark - 导航栏日间、黑夜模式
......
{
"images" : [
{
"filename" : "slideIcon.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "slideIcon@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "slideIcon@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
......@@ -18,6 +18,13 @@ FOUNDATION_EXTERN NSString * const FirstShowPrivacy;
// 引导页
FOUNDATION_EXTERN NSString * const IsFirstGuide;
// 主体模式自动切换标记
FOUNDATION_EXTERN NSString * const ThemeAutoSwitch;
FOUNDATION_EXTERN NSString * const StartTime1;
FOUNDATION_EXTERN NSString * const ExpireTime1;
FOUNDATION_EXTERN NSString * const StartTime2;
FOUNDATION_EXTERN NSString * const ExpireTime2;
#pragma mark - 第三方平台配置
/** 微信开放平台AppID */
FOUNDATION_EXTERN NSString * const WeChatAppID;
......
......@@ -14,6 +14,12 @@ NSString * const FirstShowPrivacy = @"FirstShowPrivacy";
NSString * const IsFirstGuide = @"isFirstGuide";
NSString * const ThemeAutoSwitch = @"themeAutoSwitch";
NSString * const StartTime1 = @"21:00:00";
NSString * const ExpireTime1 = @"23:59:59";
NSString * const StartTime2 = @"00:00:00";
NSString * const ExpireTime2 = @"06:00:00";
NSString * const WeChatAppID = @"wx4cdd4760092cdfdf";
NSString * const WeChatAppSecret = @"";
NSString * const UNIVERSAL_LINK = @"https://www.cbti.cn/sleep_apple/";
......
......@@ -23,6 +23,7 @@
#import "UILabel+Extras.h"
#import "UIButton+Extras.h"
#import "NSString+Extras.h"
#import "NSDate+Extras.h"
#import "NaviBarHandlerProtocol.h"
#import "BaseNaviController.h"
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!