How can I add a UIToolbar to a UIViewController?

落爺英雄遲暮 提交于 2019-12-12 16:03:01

问题


I have a UIViewController. I want to add a UIToolbar to the bottom, but IB is not letting me. How can I achieve this?

Note: The UIViewController is part of a UINavigationController. I'm not sure if this affects the visibility of the toolbar.


回答1:


Starting from iOS 3.0 you can set toolbar items you want using following UIViewController's method:

- (void)setToolbarItems:(NSArray *)toolbarItems animated:(BOOL)animated

of simply set or override toolbarItems property.

And toolbar will appear automatically if you put your view controller inside navigation controller.




回答2:


You can't add toolbar in IB, in IB all you can do is - set a dummy toolbar / navigation bar / tabBar etc. so that you can simulate them to arrange your view's subviews appropriately.

To set the toolbar for that viewController, you have to fill the UIViewController's:

setToolbarItems:animated:

or

@property(nonatomic, retain) NSArray *toolbarItems

so this toolbar and its items will be displayed when your viewController is presented.



来源:https://stackoverflow.com/questions/6746384/how-can-i-add-a-uitoolbar-to-a-uiviewcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!