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业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
Linux三剑客之awk详解
第一篇 awk简介与表达式实例 一种名字怪异的语言 模式扫描和处理,处理数据和生成报告。 awk不仅仅是linux系统中的一个命令,而且是一种编程语言;它可以用来处理数据和生成报告(excel);处理的数据可以是一个或多个文件;可以是直接来自标准输入,也可以通过管道获取标准输入;awk可以在命令行上直接编辑命令进行操作,也可以编写成awk程序来进行更为复杂的运用。 sed处理stream editor文本流,水流。 一、awk环境简介 本文涉及的awk为gawk,即GNU版本的awk。 [root@creditease awk]# cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core) [root@creditease awk]# uname -r 3.10.0-862.el7.x86_64 [root@creditease awk]# ll `which awk` lrwxrwxrwx. 1 root root 4 Nov 7 14:47 /usr/bin/awk -> gawk [root@creditease...
- 下一篇
2019 Vue开发指南:你都需要学点啥?
转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具、解决方案和服务,赋能开发者。 原文出处:https://dzone.com/articles/vue-development-in-2019-what-you-need-to-know 如果您是Vue开发的新手,您可能已经听过很多关于它的专业术语了,例如:单页面应用程序、异步组件、服务器端呈现等。 另外您可能还经常听到和Vue一起提到的工具和库,如Vuex、Webpack、Vue CLI和Nuxt。 也许您在面对这些未知的术语和工具时会感到无助和绝望,没关系,您并不孤单,因为这是所有新手在初次接触Vue时都会有的感受。 但如果您试图要一次掌握所有这些内容,那么这些庞大的体系很可能会压垮你。为此,我在这里将为大家展示一个“知识图表”,它包含了所有在专业Vue开发过程中的关键部分。您可以参考这个图为您在2019学习Vue的过程中指引方向。 0. JavaScript和Web开发基础 如果我让你用英文去阅读纯英文书籍,那么你应该先要学习英文,对吗? 同样,Vue是一个用于构建Web用户界面的JavaScript框架。在开始使用Vu...
相关文章
文章评论
共有0条评论来说两句吧...