簡體   English   中英

無法在 iOS 13 中設置標簽欄陰影圖像

[英]Can't set tab bar shadow image in iOS 13

在 iOS13 之前,我使用下面的代碼來移除標簽欄上邊框:

UITabBar.appearance().shadowImage = UIImage()
UITabBar.appearance().backgroundImage = UIImage()

但它不適用於 iOS13,我正在尋找解決方案。 你有什么想法嗎?

Swift 4+:

在您的 TabBarController class 中寫下:

 if #available(iOS 13, *) {
        let appearance = self.tabBar.standardAppearance.copy()
        appearance.backgroundImage = UIImage()
        appearance.shadowImage = UIImage()
        appearance.shadowColor = .clear
        self.tabBar.standardAppearance = appearance
    } else {
        self.tabBar.shadowImage = UIImage()
        self.tabBar.backgroundImage = UIImage()
    }

對於標題調整使用這個:

appearance.stackedLayoutAppearance.normal.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -12)

用於物鏡 C

  if (@available(iOS 13.0, *)) {
    UITabBarAppearance* appearance =  self.tabBar.standardAppearance.copy;
    appearance.backgroundImage = [UIImage new];
    appearance.shadowImage = [UIImage new];
    appearance.shadowColor = [UIColor clearColor];
    // Title adjustment
    appearance.stackedLayoutAppearance.normal.titlePositionAdjustment = UIOffsetMake(0, -12);
    self.tabBar.standardAppearance = appearance;
} else {
    self.tabBar.shadowImage = [UIImage new];
    self.tabBar.backgroundImage = [UIImage new];
}

在 iOS 13 中,您可以使用基於外觀的方法以及用於配置透明度的內置方法:

    if #available(iOS 13, *) {
        let appearance = self.tabBar.standardAppearance.copy()
        appearance.configureWithTransparentBackground()
        tabBar.standardAppearance = appearance
    } else {
        tabBar.backgroundImage = UIImage()
        tabBar.shadowImage = UIImage()
        tabBar.barTintColor = UIColor.clear
    }

要再次更改它,您可以使用 configureWithDefaultBackground() 執行相同操作:

    if #available(iOS 13, *) {
        let appearance = self.tabBar.standardAppearance.copy()
        appearance.configureWithDefaultBackground()
        tabBar.standardAppearance = appearance
    } else {
        tabBar.barTintColor = nil
        tabBar.backgroundImage = nil
        tabBar.shadowImage = nil
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM