There are a number of questions regarding the height of UIToolbar
, but I don't see one where the height is obtained dynamically. Is there a way to create a UIToolbar
with the correct default height?
Programmatically create UIToolbar with default height
Create the toolbar with 0 height, then call sizeToFit
. The toolbar will then have the default height.
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, width, 0)];
[toolbar sizeToFit];
Swift version:
let toolbar = UIToolbar(frame: CGRect(x: 0, y: 0, width: width, height: 0))
toolbar.sizeToFit()
Would the behaviour be any different if initialized with a non-zero height? –
Barolet
@Barolet is been a long time since I wrote this up, but my guess is that it doesn't matter. –
Sjoberg
if you are using UINavigationController
navigationController?.isToolbarHidden = false
This will give default navigation controller toolbar with default height
© 2022 - 2024 — McMap. All rights reserved.