navigation bar 分为三个部分,左按钮,右按钮和中间的View.
在Controller中可以通过以三个方式来引用:
typedef enum { UIBarButtonSystemItemDone, UIBarButtonSystemItemCancel, UIBarButtonSystemItemEdit, UIBarButtonSystemItemSave, UIBarButtonSystemItemAdd, UIBarButtonSystemItemFlexibleSpace, UIBarButtonSystemItemFixedSpace, UIBarButtonSystemItemCompose, UIBarButtonSystemItemReply, UIBarButtonSystemItemAction, UIBarButtonSystemItemOrganize, UIBarButtonSystemItemBookmarks, UIBarButtonSystemItemSearch, UIBarButtonSystemItemRefresh, UIBarButtonSystemItemStop, UIBarButtonSystemItemCamera, UIBarButtonSystemItemTrash, UIBarButtonSystemItemPlay, UIBarButtonSystemItemPause, UIBarButtonSystemItemRewind, UIBarButtonSystemItemFastForward, UIBarButtonSystemItemUndo, // available in iPhone 3.0 UIBarButtonSystemItemRedo, // available in iPhone 3.0 } UIBarButtonSystemItem;
[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPlay target:nil action:NULL] autorelease];
typedef enum { UIBarButtonItemStylePlain, // shows glow when pressed UIBarButtonItemStyleBordered, UIBarButtonItemStyleDone, } UIBarButtonItemStyle;
typedef enum { UIBarStyleDefault = 0, UIBarStyleBlack = 1, UIBarStyleBlackOpaque = 1, // Deprecated. Use UIBarStyleBlack UIBarStyleBlackTranslucent = 2, // Deprecated. Use UIBarStyleBlack and set the translucent property to YES } UIBarStyle;
NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:4]; UIBarButtonItem *flexibleSpaceItem; flexibleSpaceItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:NULL] autorelease]; [buttons addObject:flexibleSpaceItem]; [flexibleSpaceItem release]; UIBarButtonItem *item; item = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"down.png"] style:UIBarButtonItemStylePlain target:self action:@selector(decrement:)]; [buttons addObject:item]; [item release]; item = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"up.png"] style:UIBarButtonItemStylePlain target:self action:@selector(increment:)]; [buttons addObject:item]; [item release]; item = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPlay target:nil action:NULL] autorelease]; [buttons addObject:item]; [item release]; flexibleSpaceItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:NULL] autorelease]; [buttons addObject:flexibleSpaceItem]; [flexibleSpaceItem release]; UIToolbar *toolbar = [[UIToolbar alloc] init]; toolbar.barStyle = UIBarStyleBlackOpaque; [toolbar setItems:buttons animated:YES]; [toolbar sizeToFit];