簡體   English   中英

標簽欄高度和按鈕大小-固定?

[英]Tab Bar Height and button size - Fixed?

我有一個自定義的標簽欄控制器,我想向其中添加2個按鈕。 1個放大的中心按鈕和左側的1個按鈕,用於創建側邊漢堡菜單,該菜單從標簽欄(而不是頂部導航欄)啟動。

我正試圖以編程方式獲取標簽欄的高度,以便我可以從中設置按鈕的高度。 所以我閱讀並嘗試了以下無效的代碼。

self.tabBarController?.tabBar.frame.size.height

我在其他地方看到,無論設備如何,標簽欄始終是固定的49像素?

如果是這樣,使用類似的方法是否安全:

menuButtonFrame.origin.y = self.view.bounds.height - (CGFloat(49) - menuButtonFrame.size.height) / 2

設置按鈕的位置? (黑匣子)其位置尚未正確

還想知道標簽欄按鈕的默認值是多少?

在此處輸入圖片說明

像這樣創建一個UIView並根據需要設置中心項目的高度。

在此處輸入圖片說明

然后在TabbarView Controller中。 將此視圖添加到選項卡視圖中。

UITabBar.appearance().shadowImage = UIImage()

        customNavBar = NSBundle.mainBundle().loadNibNamed("CustomTabBarView", owner: self, options: nil)[0] as! UIView

        bdNavBar.translatesAutoresizingMaskIntoConstraints = false

        self.tabBar.addSubview(customNavBar)

然后將約束添加到自定義選項卡。

self.view.addConstraint(NSLayoutConstraint(item: customNavBar, attribute: .Left, relatedBy: .Equal, toItem: self.view, attribute: .Left, multiplier: 1.0, constant:  0))
self.view.addConstraint(NSLayoutConstraint(item: customNavBar, attribute: .Right, relatedBy: .Equal, toItem: self.view, attribute: .Right, multiplier: 1.0, constant:  0))
self.view.addConstraint(NSLayoutConstraint(item: customNavBar, attribute: .Bottom, relatedBy: .Equal, toItem: self.view, attribute: .Bottom, multiplier: 1.0, constant:  0))
bdNavBar.addConstraint(NSLayoutConstraint(item: customNavBar, attribute: NSLayoutAttribute.Height, relatedBy: .Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1.0, constant:  50))        
self.tabBar.bringSubviewToFront(customNavBar)

暫無
暫無

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

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