简体   繁体   中英

Can I add two right-hand buttons to a UINavigationBar?

I would like to be able to have a UINavigationBar with a left-hand UIBarButtonItem, two right-hand UIBarButtonItems, and a title.

I have resorted to using a UIToolBar to simulate this, but the toolbar looks slightly different than the UINavigationBar, and it also won't bevel UIBarButtonSystemItems.

Is there a way to make a UINavigationBar with three UIBarButtonItems?

There's no way to do this using all native graphics. However, if you're willing to get your hands a little dirty in Acorn or Photoshop, you can create your buttons images there, and then add several buttons to a UIView, encase that in a UIBarBUttonItem, and set it to be the leftBarButtonItem.

This question tackles the item as well: How to add 2 buttons into the UINavigationbar on the right side without IB?

Since iOS5 it's easily possible ( https://developer.apple.com/library/ios/documentation/uikit/reference/UINavigationItem_Class/Reference/UINavigationItem.html#//apple_ref/occ/instm/UINavigationItem/setRightBarButtonItems:animated : ) :

setRightBarButtonItems:animated:

Sets the right bar button items, optionally animating the transition to the new items. - (void)setRightBarButtonItems:(NSArray *)items animated:(BOOL)animated

Discussion

If two navigation items have the same custom left or right bar button items, those bar button items remain stationary during the transition when the navigation item is pushed or popped.

Availability Available in iOS 5.0 and later. Declared In UINavigationBar.h

I posted code to add two buttons to the right of the navigationBar . You can set barStyle = -1 instead of subclassing UIToolbar .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM