簡體   English   中英

UITabBar有問題

[英]Having an issue with UITabBar

我已經在File Inspector中嘗試過安全區域復選框。 但效果不佳。 再次向我展示了這個問題。有什么完美的解決方案。

在此處輸入圖片說明

這是具有所有約束的圖像。

嘗試將所有約束的值都設置為0,同樣的問題是圖像會剛好位於標簽上方或圖像不合適,對於約束,如果要為頂部設置約束,則需要為約束設置相同的約束。底部...

我希望這可以幫助您。

不要使用“寬松”的標簽欄。 您只能使用UITabBarController提供的標簽欄。 使用UITabBarController重組您的體系結構,並且選項卡欄在iPhone X上看起來正確(並且尺寸通常正確,例如,在iPhone上,肖像比橫向更高)。

請刪除標簽欄的高度限制。 由於與其他iPhone設備相比,iPhone X中選項卡欄的默認高度不同。

希望這會幫助你。

您可以使用此代碼更新標簽欄的高度

let ApplicationDelegate = UIApplication.shared.delegate as! AppDelegate
DispatchQueue.main.async {
if #available(iOS 11.0, *) {
    if UIDevice().userInterfaceIdiom == .phone, ApplicationDelegate.window!.safeAreaInsets.top > 0 {
        let kTabBarHeight: CGFloat = 49.0/*default tab bar height*/ + ApplicationDelegate.window!.safeAreaInsets.bottom
        self.tabBar.frame = CGRect(x: 0, y: self.view.frame.size.height - kTabBarHeight, width: self.view.frame.size.width, height: kTabBarHeight);
    }
}
}

希望對您有幫助。

不要在UITabBar控制器中為圖像添加任何約束,並更新UITabbar及其用於iPhoneX的項目的高度。

`override func viewWillLayoutSubviews() {
    var newTabBarFrame = tabBar.frame
    var newTabBarHeight: CGFloat = 60

    if UIDevice.current.iPhoneX{
        newTabBarHeight = 102
    }
    newTabBarFrame.size.height = newTabBarHeight
    newTabBarFrame.origin.y = self.view.frame.size.height - newTabBarHeight
    tabBar.frame = newTabBarFrame
    let numberOfItems = CGFloat(tabBar.items!.count)
    let customColor = UIColor.lightGray.cgColor
    let tabBarItemSize = CGSize(width: tabBar.frame.width / numberOfItems, height: tabBar.frame.height)
    tabBar.selectionIndicatorImage = UIImage.imageWithColor(color: customColor, size: tabBarItemSize).resizableImage(withCapInsets: UIEdgeInsets.zero)
    // remove default border
    tabBar.frame.size.width = self.view.frame.width + 4
    tabBar.frame.origin.x = -2
}`

暫無
暫無

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

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