Programmatically create a UIToolbar with a standard height

There are a number of questions regarding the height of the UIToolbar , but I do not see where the height is obtained dynamically. Is there a way to create a UIToolbar with the correct default height?

+2
source share
2 answers

Create a toolbar with a height of 0, then call sizeToFit . Then the toolbar will have a default height.

 UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, width, 0)]; [toolbar sizeToFit]; 

Quick version:

 let toolbar = UIToolbar(frame: CGRect(x: 0, y: 0, width: width, height: 0)) toolbar.sizeToFit() 
+1
source

if you are using a UINavigationController

 navigationController?.isToolbarHidden = false 

This will give a default navigation controller toolbar with a default value

0
source

Source: https://habr.com/ru/post/902558/


All Articles