iOS开发 Xcode13-iOS 15适配(OC、Swift)

iOS开发 Xcode13-iOS 15适配(OC、Swift),第1张

升级Xcode13后,编译的APP的导航栏(nav、tabbar)、tableview的section head会出现一些显示问题,在这里给出一些处理方法。

UINavigationBar Swift
if #available(iOS 13.0, *) {
    let appearance = UINavigationBarAppearance()
    // 设置导航栏背景色
    appearance.backgroundColor = .white
    // 去除导航栏阴影(如果不设置clear,导航栏底下会有一条阴影线)
    appearance.shadowColor = UIColor.clear
    // 字体颜色
    appearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
    // 带scroll滑动的页面
    navigationController?.navigationBar.scrollEdgeAppearance = appearance
    // 常规页面
    navigationController?.navigationBar.standardAppearance = appearance 
}
Objective-C
if (@available(iOS 13.0, *)) {
    UINavigationBarAppearance * appearance = [[UINavigationBarAppearance alloc] init];
    // 背景色
    appearance.backgroundColor = [UIColor whiteColor];
    // 去除导航栏阴影(如果不设置clear,导航栏底下会有一条阴影线)
    appearance.shadowColor = [UIColor clearColor];
    // 字体颜色
    appearance.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor redColor]};
    // 带scroll滑动的页面
    self.navigationController.navigationBar.scrollEdgeAppearance = appearance;
    // 常规页面
    self.navigationController.navigationBar.standardAppearance = appearance;
}
UITabbar Swift
if #available(iOS 13.0, *) { 
    let appearance = UITabBarAppearance()
    // 背景色
    appearance.backgroundColor = .white
    tabBar.standardAppearance = appearance
    if #available(iOS 15.0, *) {
        tabBar.scrollEdgeAppearance = appearance
    }
} 
Objective-C
if (@available(iOS 13.0, *)) { 
    UITabBarAppearance *appearance = [[UITabBarAppearance alloc] init];
    // 背景色
    appearance.backgroundColor = [UIColor whiteColor];
    self.tabBar.standardAppearance = appearance; 
    if (@available(iOS 15.0, *)) {
        self.tabBar.scrollEdgeAppearance = appearance;
    }
}
TableView

iOS 15 的 UITableView 新增了一条新属性:sectionHeaderTopPadding, 默认会给每一个 section header 增加 22px。

Swift
if #available(iOS 15.0, *) {
    tableView.sectionHeaderTopPadding = 0
}
Objective-C
if (@available(iOS 15.0, *)) { 
    tableView.sectionHeaderTopPadding = 0;
}

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/996850.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-21
下一篇2022-05-21

发表评论

登录后才能评论

评论列表(0条)

    保存