xcode 13更新后出現(xiàn)的bug

UITableView sectionHeader下移22像素?

swift

if#available(iOS15.0, *) {

            self.mainTableView.sectionHeaderTopPadding =0        }

OC
 if(@available(iOS15.0, *)) {

            _downloadTableView.sectionHeaderTopPadding = 0;

        }

導(dǎo)航背景顏色修改無效?

swift

if #available(iOS 15.0, *) {

            let appearance = UITabBarAppearance()

            appearance.configureWithOpaqueBackground()

            if darkMode {

                appearance.backgroundColor = UIColor.darkBackgroundColour

            } else {

                appearance.backgroundColor = .white

            }

            appearance.shadowImage = nil

  appearance.shadowColor = nil

            appDelegate.tabBarController.tabBar.standardAppearance = appearance

            appDelegate.tabBarController.tabBar.scrollEdgeAppearance = appDelegate.tabBarController.tabBar.standardAppearance

        }



OC

if (@available(iOS 15.0, *)) {

        UINavigationBarAppearance *barApp = [UINavigationBarAppearance new];

        barApp.backgroundColor = [[UIColor blueColor] colorWithAlphaComponent:0.5];

        self.navigationController.navigationBar.scrollEdgeAppearance = barApp;

        self.navigationController.navigationBar.standardAppearance = barApp;
}

UINavigationBar
UINavigationBar 部分屬性的設(shè)置在 iOS15 上是無效的,iOS15navigationBar 的相關(guān)屬性設(shè)置要通過實例 UINavigationBarAppearance 來實現(xiàn),UINavigationBarAppearance 是 iOS13 更新的 API,應(yīng)該有人已經(jīng)在用,我們的應(yīng)用兼容 iOS10 以上,對于導(dǎo)航欄的設(shè)置還沒有使用 UINavigationBarAppearance,如今在 iOS15 上失效,所以對于呈現(xiàn)的問題,做如下適配:

解決方法

主要是以下兩個屬性 (UINavigationController 的屬性)

// 靜止樣式
self.navigationBar.standardAppearance;
// 滾動樣式
self.navigationBar.scrollEdgeAppearance;
swift
        if #available(iOS 13.0, *) {
            let appearance = UINavigationBarAppearance()
              // 設(shè)置導(dǎo)航欄背景色
            appearance.backgroundColor = .white
              // 去除導(dǎo)航欄陰影(如果不設(shè)置clear,導(dǎo)航欄底下會有一條陰影線)
            appearance.shadowColor = UIColor.clear
              // 字體顏色、尺寸等
            appearance.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
            // 帶scroll滑動的頁面
            navigationController?.navigationBar.scrollEdgeAppearance = appearance
            // 常規(guī)頁面
            navigationController?.navigationBar.standardAppearance = appearance 
        }

OC 
    if (@available(iOS 13.0, *)) {
        UINavigationBarAppearance * appearance = [[UINavigationBarAppearance alloc] init];
        // 背景色
        appearance.backgroundColor = [UIColor whiteColor];
        // 去除導(dǎo)航欄陰影(如果不設(shè)置clear,導(dǎo)航欄底下會有一條陰影線)
        appearance.shadowColor = [UIColor clearColor];
        // 設(shè)置字體顏色、尺寸等
        appearance.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor redColor]};
        // 帶scroll滑動的頁面
        self.navigationController.navigationBar.scrollEdgeAppearance = appearance;
        // 常規(guī)頁面
        self.navigationController.navigationBar.standardAppearance = appearance;
    }

導(dǎo)航欄隱藏的返回按鈕失效問題
swift

//appdelegate全局設(shè)置
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-200, 0) forBarMetrics:UIBarMetricsDefault];
    // iOS 15適配
    if (@available(iOS 13.0, *)) {
        UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
        [appearance setBackgroundColor:[UIColor whiteColor]];
        // UINavigationBarAppearance 會覆蓋原有的導(dǎo)航欄設(shè)置,這里需要重新設(shè)置返回按鈕隱藏,不隱藏可注釋或刪掉
        appearance.backButtonAppearance.normal.titlePositionAdjustment = UIOffsetMake(-200, 0);

        [[UINavigationBar appearance] setScrollEdgeAppearance: appearance];
        [[UINavigationBar appearance] setStandardAppearance:appearance];
    }

UITabbar
tabbar 背景顏色設(shè)置失效

        if #available(iOS 13.0, *) { 
            let appearance = UITabBarAppearance()
           // 背景色
            appearance.backgroundColor = .white
            tabBar.standardAppearance = appearance
            if #available(iOS 15.0, *) {
                tabBar.scrollEdgeAppearance = appearance
            }
        } 

OC

    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;
        }
    }

iOS 15 的 UITableView 新增了一條新屬性:sectionHeaderTopPadding, 默認會給每一個 section header 增加一個高度,當(dāng)我們使用 UITableViewStylePlain 初始化 UITableView 的時候,能發(fā)現(xiàn) sectionHeader 增高了 22px。

/// Padding above each section header. The default value is `UITableViewAutomaticDimension`.
    @available(iOS 15.0, *)
    open var sectionHeaderTopPadding: CGFloat
    
//iOS 15中tableView會給每一個section的頂部(header以上)再加上一個22像素的高度,形成一個section和section之間的間距

  if #available(iOS 15.0, *) {
      tableView.sectionHeaderTopPadding = 0
  }

//或者appdelegate全局設(shè)置
  if #available(iOS 15.0, *) { 
     UITableView.appearance().sectionHeaderTopPadding = 0
   }
OC
    if (@available(iOS 15.0, *)) { 
        tableView.sectionHeaderTopPadding = 0;
    }

 //或者appdelegate全局設(shè)置 
    if (@available(iOS 15.0, *)) {
        [UITableView appearance].sectionHeaderTopPadding = 0;
    }

原文鏈接:http://www.itdecent.cn/p/10c7921e6d76

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容