我试图做我自己的自定义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