Changing the height of UIToolbar in iOS 7
ios, ios7, toolbar, uitoolbar
Solution
Following the @Antoine suggestion using `sizeThatFits`, here is my Toolbar subclass with an height of 64:
import UIKit
class Toolbar: UIToolbar {
override func layoutSubviews() {
super.layoutSubviews()
frame.size.height = 64
}
override func sizeThatFits(size: CGSize) -> CGSize {
var size = super.sizeThatFits(size)
size.height = 64
return size
}
}
Then, when initializing the navigation controller, I say it should use that class:
let navigationController = UINavigationController(navigationBarClass: nil, toolbarClass: Toolbar.self)
Problem
I am trying to change the height of my UIToolbar in a new iOS 7 project but I am not able to. I am using a UINavigationController to manage a couple of UIViewController. I tried setting the frame for the toolbar via the navigation controller but alas, the toolbar property is read-only. I looked at "Is there a way to change the height of a UIToolbar?" but that did not work. I tried subclassing UIToolbar, forcing a custom height and setting the right class in the Storyboard but that did not work neither, height keeps on being 44px. I thought about auto-layout could not set any constraint on the size of the toolbar, every field is disabled. I can set a custom view in a UIBarButtonItem with a bigger height than the toolbar. The big item will be correctly rendered but it will overflow from the toolbar. This is the best I could do: screenshot Is it actually possible to change the height of the UIToolbar in iOS 7? Or am I supposed to create a bunch of custom items to mimic it?