问题
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