更新iOS13后的变化
1.暗黑模式(Dark Mode)
iOS更新之后,发现cell背景变黑,UILabel字体变白,开始各种改颜色,后来发现另一个升级的手机没事,原理是iOS13暗黑模式导致颜色变黑。
最简单的处理的处理方法是在Info.plist文件中添加Key:User Interface Style,值类型设置为String,值为Light,就可以不管在什么模式下,软件只支持浅色模式,不支持黑暗模式,如果只想软件支持黑暗模式,则可以把类型设置为:Dark
<key>UIUserInterfaceStyle</key>
<string>Light</string>
注意:使用UIUserInterfaceStyle,如果上传至appstore,需要使用xcode11.0以上版本打包ipa包。如果使用xcode10打包,UIUserInterfaceStyle会校验不通过。从Xcode11开始,Application Loader不再集成在Xcode中,Xcode11找不到Application Loader解决方式。
2. iOS13中presentViewController
更新了Xcode11之后,在iOS13中运行代码发现presentViewController和之前弹出的样式不一样。
会出现这种情况是主要是因为我们之前对UIViewController里面的一个属性,即modalPresentationStyle(该属性是控制器在模态视图时将要使用的样式)没有设置需要的类型。在iOS13中modalPresentationStyle的默认改为UIModalPresentationAutomatic,而在之前默认是UIModalPresentationFullScreen。
/*
Defines the presentation style that will be used for this view controller when it is presented modally. Set this property on the view controller to be presented, not the presenter.
If this property has been set to UIModalPresentationAutomatic, reading it will always return a concrete presentation style. By default UIViewController resolves UIModalPresentationAutomatic to UIModalPresentationPageSheet, but other system-provided view controllers may resolve UIModalPresentationAutomatic to other concrete presentation styles.
Defaults to UIModalPresentationAutomatic on iOS starting in iOS 13.0, and UIModalPresentationFullScreen on previous versions. Defaults to UIModalPresentationFullScreen on all other platforms.
*/
@property(nonatomic,assign) UIModalPresentationStyle modalPresentationStyle API_AVAILABLE(ios(3.2));
要改会原来模态视图样式,我们只需要把UIModalPresentationStyle设置为UIModalPresentationFullScreen即可。
ViewController *vc = [[ViewController alloc] init];
vc.title = @"presentVC";
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
nav.modalPresentationStyle = UIModalPresentationFullScreen;
[self.window.rootViewController presentViewController:nav animated:YES completion:nil];
3.私有KVC
OS 13上不允许使用:valueForKey、setValue: forKey获取和设置私有属性,需要使用其它方式修改,不然会奔溃
如:
[textField setValue:[UIColor red] forKeyPath:@"_placeholderLabel.textColor"];
//UITextField有个attributedPlaceholder的属性,我们可以自定义这个富文本来达到我们需要的结果,替换为
textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"输入"attributes:@{NSForegroundColorAttributeName: [UIColor red]}];
iOS 13 通过 KVC 方式修改私有属性,有 Crash 风险,谨慎使用!并不是所有KVC都会Crash,要尝试!