iOS 13 适配

转自iOS 13采坑记录
iOS 13适配总结

  1. UIViewController Present出来的样式修改

    iOS 13默认的modalPresentationStyle是UIModalPresentationAutomatic,可能不符合我们的要求,改回之前的模式要用UIModalPresentationFullScreen.

新写一个UIViewController的Category,改变modalPresentationStyle的返回结果

1
2
3
4
5
6
7
@implementation UIViewController(Category)

- (UIModalPresentationStyle)modalPresentationStyle {
return UIModalPresentationFullScreen;
}

@end
  1. “NSGenericException” -reason: “Accress to UITextField’s _placeholderLabel ivar is prohibited.”
    设置TextField的placeholder颜色在iOS 13 Crash,即下面的方法会崩溃
1
[textField setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];

修改:

1
2
3
4
5
#import <objc/runtime.h>

Ivar ivar = class_getInstanceVariable([UITextField class], "_placeholderLabel");
UILabel *placeholderLabel = object_getIvar(textField, ivar);
placeholderLabel.textColor = [UIColor whiteColor];