每日一博 | iOS13 适配,夜间模式(深色模式 DarkMode)与其他
https://my.oschina.net/wintelsui/blog/3063883
iOS13 适配 夜间模式与其他
- 夜间模式
- 其他问题:presentViewController
###一 :夜间/深色模式 DarkMode
夜间模式是iOS13的重要更新之一,随之而来的是我们能从系统设置中“显示与亮度”中选择“浅色”、“深色”两种模式,并且可以设置自动切换。(“控制中心”亮度调节中也可直接调节)
已知问题:在系统设置为深色模式时候,无法更改StateBar颜色
-
如果不想适配深色模式 (1).直接在项目的plist文件中设置
<key>UIUserInterfaceStyle</key> <string>UIUserInterfaceStyleLight</string>
(2).在每个UIViewController或者BaseViewController(如果自己有的话),中设置
if (@available(iOS 13.0, *)){ self.overrideUserInterfaceStyle = UIUserInterfaceStyleLight; }
-
适配深色模式 首先我们要看一下显示模式的枚举值
typedef NS_ENUM(NSInteger, UIUserInterfaceStyle) { UIUserInterfaceStyleUnspecified, UIUserInterfaceStyleLight, UIUserInterfaceStyleDark, } API_AVAILABLE(tvos(10.0)) API_AVAILABLE(ios(12.0)) API_UNAVAILABLE(watchos);
当前API还没有提供浅色/深色模式切换时的通知,但是为UIColor添加了新方法: + (UIColor *)colorWithDynamicProvider:(UIColor * (^)(UITraitCollection *))dynamicProvider;
该方法通过一个block返回颜色,根据其中UITraitCollection参数,我们可以获取到当前系统的UIUserInterfaceStyle. 这个方法会在每次系统模式改变后回调,所以我想,我可以在一个颜色中去为当前界面做监听.
Xcode 11为xcassets带来更新以自动读取加载浅色/深色模式的资源,只要修改资源Appearances属性,来设置是否要支持浅色/深色模式,以及资源内容即可,[UIImage imageNamed:@""]会自动加载浅色/深色资源.
最后上一段 UIViewController 截图
最后最后上一段 UIViewController 代码
#import "DarkModeViewController.h" @interface DarkModeViewController () { UIImageView *_iv2; UIUserInterfaceStyle _userInterfaceStyle; } @end @implementation DarkModeViewController - (void)viewDidLoad { [super viewDidLoad]; __weak typeof(self)weakSelf = self; UIColor *backgroundColor = [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * traitCollection) { self->_userInterfaceStyle = traitCollection.userInterfaceStyle; [weakSelf performSelector:@selector(traitCollectionChanged:) withObject:traitCollection]; if (traitCollection.userInterfaceStyle == UIUserInterfaceStyleDark) { return [UIColor blueColor]; } return [UIColor yellowColor]; }]; self.view.backgroundColor = backgroundColor; UIImageView *iv = ({ UIImageView *imageView = [[UIImageView alloc] init]; [imageView setBackgroundColor:[UIColor clearColor]]; [imageView setFrame:CGRectMake(20, 100, 100, 100)]; imageView.image = [UIImage imageNamed:@"icon_star"]; imageView; }); [self.view addSubview:iv]; _iv2 = ({ UIImageView *imageView = [[UIImageView alloc] init]; [imageView setBackgroundColor:[UIColor clearColor]]; [imageView setFrame:CGRectMake(20, 240, 100, 100)]; imageView; }); [self.view addSubview:_iv2]; [self iv2updateImage]; } - (void)traitCollectionChanged:(UITraitCollection *)traitCollection{ NSLog(@"traitCollectionChanged:%ld",traitCollection.userInterfaceStyle); [self iv2updateImage]; } - (void)iv2updateImage { NSLog(@"iv2updateImage:%ld",_userInterfaceStyle); if (_userInterfaceStyle == UIUserInterfaceStyleDark) { _iv2.image = [UIImage systemImageNamed:@"star.circle.fill"]; }else{ _iv2.image = [UIImage systemImageNamed:@"star.circle"]; } } @end
###二 :其他问题
- presentViewController modalPresentationStyle参数有 iOS12 之前的UIModalPresentationFullScreen改为了UIModalPresentationPageSheet, 在需要presentViewController FullScreen样式,需要提前设置
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
OSC 周五乱弹 —— 你不会知道老板在女装大佬面前多主动
Osc乱弹歌单(2019)请戳(这里) 【今日歌曲】 @宇辰OSC :分享闻音合唱团的单曲《君をのせて(天空之城)》: 喜欢这样的合唱#今日歌曲推荐# 《君をのせて(天空之城)》- 闻音合唱团 手机党少年们想听歌,请使劲儿戳(这里) 每天给大家分享音乐, 看到别人是这么评论这种行为的。 @afterer :这个说得有道理 大家给小小编辑留言说, Osc乱弹歌单的账号是小号呀, 对对对, 当然是小号, 小小编辑也不想让你们见识到自己人格分裂的那一面。 你们能看出来巴叔是什么样的人么? @巴拉迪维 :#夏天的颜色# 我喜欢五彩斑片的世界,因为我是个花心的男人! 夏天的颜色不是在宫崎骏的动画里了么 06-21《千与千寻》上映了。 @bikaqiu:要去看 宫崎骏讲的都是温暖的故事, 你的童年被他小心翼翼的保护着, @迷茫-程序猿 :小时候家里养过一只猫和一只狗 狗总是被猫欺负 不是狗憨厚 而是斗不过猫 比如猫藏在鞋盒偷袭狗 狗只能绕着鞋盒转圈 后来狗去世了 猫没看见它去世的样子 只是没见狗回来 半年过去了 有天我故意在门口喊了声狗的名字 猫从屋里飞奔到门口左右张望 “哈哈哈哈哈……” 我家就...
- 下一篇
Oracle 发布基于 VS Code 的开发者工具,轻松使用 Oracle 数据库
Oracle 发布基于 VS Code 的开发者工具,让开发者能轻松连接 Oracle 数据库。 ▲ Oracle Developer Tools for VS Code Oracle 数据库在DB-Engines Ranking长期占据第一,对于大量开发人员来说,使用 VS Code,在创建、编写、运行以及管理你的 Oracle 数据库将会更加方便。 特性 使用 EZ Connect syntax、TNS Connect aliases或 Windows authentication 连接Oracle 数据库和 Oracle Autonomous 数据库 创建和管理所有的数据库连接 提供智能提示、语法高亮和代码片段等功能来编辑 SQL 和 PL/SQL 脚本 执行 SQL 脚本,并查看和保存运行结果 详细入门方法 文章参考
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- SpringBoot2初体验,简单认识spring boot2并且搭建基础工程
- CentOS7,8上快速安装Gitea,搭建Git服务器
- Linux系统CentOS6、CentOS7手动修改IP地址
- SpringBoot2配置默认Tomcat设置,开启更多高级功能
- MySQL8.0.19开启GTID主从同步CentOS8
- Red5直播服务器,属于Java语言的直播服务器
- SpringBoot2更换Tomcat为Jetty,小型站点的福音
- SpringBoot2整合Redis,开启缓存,提高访问速度
- SpringBoot2整合Thymeleaf,官方推荐html解决方案
- CentOS7,CentOS8安装Elasticsearch6.8.6