Xcode11 + iOS13适配

参考

https://juejin.im/post/5d85c3fde51d453b7779d604#heading-28
https://www.jianshu.com/p/2ac8dbdcc88f

  • UISearchBar适配
获取textField使用 
#import "UISearchBar+Extension.h"
UITextField *searchField = [_searchBar bp_getSearchTextField];

获取placeholder使用
#import "UITextField+BPAdd.h"
UILabel *placeholderLB = [searchField bp_getPlaceholderLabel];
- (UITextField *)bp_getSearchTextField {
#ifdef __IPHONE_13_0
    if (@available(iOS 13.0, *)) {
        return self.searchTextField;
    }
#endif
    return [self valueForKey:@"_searchField"];
}

- (UILabel *)bp_getPlaceholderLabel {
#ifdef __IPHONE_13_0
    if (@available(iOS 13.0, *)) {
        Ivar ivar = class_getInstanceVariable([UITextField class], "_placeholderLabel");
        UILabel *placeholderLabel = object_getIvar(self, ivar);
        return placeholderLabel;
    }
#endif
    return [self valueForKeyPath:@"_placeholderLabel"];
}
  • presentVC模态弹出页面设置全屏,alertVC可以不设置
UIViewController *vc = [[UIViewController alloc] init];
vc.modalPresentationStyle = UIModalPresentationFullScreen;
[fromController presentViewController:vc animated:YES completion:nil];
  • 推送deviceToken解码兼容处理
if (@available(iOS 13.0, *)) {
    const unsigned char *dataBuffer = (const unsigned char *)deviceToken.bytes;
    NSMutableString *myToken  = [NSMutableString stringWithCapacity:(deviceToken.length * 2)];
    for (int i = 0; i < deviceToken.length; i++) {
        [myToken appendFormat:@"%02x", dataBuffer[i]];
    }
    return (NSString *)[myToken copy];
} else {
    NSCharacterSet *characterSet = [NSCharacterSet characterSetWithCharactersInString:@"<>"];
    NSString *myToken = [[deviceToken description] stringByTrimmingCharactersInSet:characterSet];
    return [myToken stringByReplacingOccurrencesOfString:@" " withString:@""];
}
  • UITabbar 分割线自定义
if (@available(iOS 13, *)) {
    #ifdef __IPHONE_13_0
    UITabBarAppearance *appearance = [self.tabBar.standardAppearance copy];
    appearance.backgroundImage = [UIImage new];
    appearance.shadowImage = [UIImage imageNamed:@"Dotted_Line"];
    appearance.shadowColor = [UIColor clearColor];
    self.tabBar.standardAppearance = appearance;
    #endif
} else {
    self.tabBar.backgroundImage = [UIImage new];
    self.tabBar.shadowImage = [UIImage imageNamed:@"Dotted_Line"];
}
  • 禁用暗黑模式

Info.plist内全局禁用

  • 状态条设置为黑色有变化
[UIApplication sharedApplication].statusBarStyle = [UIUtility getStatusBarDarkContentStyle];

#pragma mark 获取statusBar的黑色状态枚举值
+ (UIStatusBarStyle)getStatusBarDarkContentStyle {
#ifdef __IPHONE_13_0
    if (@available(iOS 13.0, *)) {
        return UIStatusBarStyleDarkContent;
    } else {
        return UIStatusBarStyleDefault;
    }
#else
    return UIStatusBarStyleDefault;
#endif
}
  • UITextFileds 的 leftView/rightView

不能直接使用UIImageView、UIButton,应该用UIView包一层

你可能感兴趣的:(Xcode11 + iOS13适配)