Preston Price
Preston Price

Reputation: 325

Error creating a UINavigationBar in custom UINavigationController class

I have a custom UINavigationController which I access from my storyboard and I want to customize the height of the nav bar by creating a custom nav bar. Here is what I have so far:

var navBar = UINavigationBar(frame: CGRect(x: 0.0, y: 0.0, width: UIScreen.main().bounds.width, height: 70.0))
navBar.barTintColor = UIColor(red: 155.0/255.0, green: 155.0/255.0, blue: 155.0/255.0, alpha: 1.0)
super.init(navigationBarClass: navBar, toolbarClass: nil)

In the last line I am getting this error

Cannot convert value of type 'UINavigationBar' to expected argument type 'AnyClass?'

Anyone know why? Could it be a bug. I am using Xcode 8 beta and Swift 3

Upvotes: 4

Views: 571

Answers (1)

Andrew Bogaevskyi
Andrew Bogaevskyi

Reputation: 2615

super.init(navigationBarClass: expects a class (AnyClass) as parameter. You have an object navBar which is object (not class) of UINavigationBar class and you are trying to set object to class parameter. Use next for correct initialising:

super.init(navigationBarClass: UINavigationBar.self, toolbarClass: nil)

For bar height you could try to use something like this: https://stackoverflow.com/a/20440989/2739795

Upvotes: 3

Related Questions