[英]Setting different heights of TabBar depending on screen size Swift
我正在使用 ESTabBarController 在我的應用程序中創建自定義標簽欄。 但是,當我設置它時,文本要么不顯示,要么被向上滑動主頁欄覆蓋。 我嘗試使用 if 來檢查屏幕尺寸是否 == 到其中一種屏幕尺寸,但仍無法正確顯示。
override func viewWillLayoutSubviews() {
// Set different tabBar height for Phone X
var heightOffset: CGFloat = 5
if UIDevice.current.userInterfaceIdiom == .phone && (UIScreen.main.nativeBounds.height == 2436 || UIScreen.main.nativeBounds.height == 1792 || UIScreen.main.nativeBounds.height == 2688) {
heightTabBar = CGFloat(60)
heightOffset = 20
}
tabBar.frame = CGRect(
origin: CGPoint(x: 0, y: view.frame.size.height - heightTabBar - heightOffset),
size: CGSize(width: UIScreen.main.bounds.width, height: heightTabBar)
)
tabBar.barTintColor = ThemeManager.viewGradientColour2
//add line in itemBar
bottomLineViewItemBar.frame = CGRect(x: 0, y: tabBar.bounds.height, width: tabBar.bounds.width, height: heightOffset)
bottomLineViewItemBar.backgroundColor = ThemeManager.viewGradientColour2
tabBar.addSubview(bottomLineViewItemBar)
}
首先,我會以不同的方式使用var height = UIScreen.main.bounds.size.height
。 要分配 TabBar 的高度,我將使用heightTabBar = CGFloat(0.1*height)
。 這意味着 TabBar 將是屏幕高度的 10%(您可以更改該值)。
此外,您可以運行safe_bottom = UIApplication.shared.windows[0].safeAreaInsets.bottom
,以避免字母被向上滑動的主頁欄重疊。 safe_bottom
具有從屏幕底部到用戶與您的 UI 交互的屏幕部分的距離。 因此,您只需將safe_bottom
放置在距屏幕底部安全底部的高度(以像素為單位)處。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.