我試圖做我自己的自定義UINavigationBar
,但我有一個問題:與我的解決方案,UINavigationBar
框架位置錯誤,它有錯誤的大小......所以它不會傳遞狀態欄。自定義UINavigationBar的壞框
所以,這是我的自定義導航欄:
import UIKit
class MainNavigationBar: UINavigationBar {
override func drawRect(rect: CGRect) {
// not translucent
translucent = false
// set background colo
backgroundColor = UIColor(red: 100/255, green: 169/255, blue: 99/255, alpha: 1)
// bar style
barStyle = UIBarStyle.Black
super.drawRect(rect)
}
}
,我通過UITabBarController
子類加載它(它加載,加載我UINavigationBar
一個UINavigationViewController
):
override func viewWillAppear(animated: Bool) {
// init recipe
let recipeItem = RecipeNavigationViewController(navigationBarClass: MainNavigationBar.self, toolbarClass: nil)
[...]
// view controllers displayed by the tab bar interface
let controllers = [recipeItem, accountItem]
self.viewControllers = controllers
}
所以用這個代碼,我的自定義UINavigationBar
沒有通過狀態欄。
我該怎麼辦?
謝謝!
謝謝!我還不知道好的做法,但我會創建一個'BaseNavigationViewController'(其中一個我將使用'self.navigationBar')其他'NavigationController'(一個用於我的MainTabViewController'的每個Tab)繼承 – Yannis