一:UINavigationBar
1.一個導航器控制個若干個視圖控制器;
2.一個導航控制器包含一個NavigationBar 和一個 toolBar;
3.UINavigationBar中的 一個按鈕是 UINavigationItem (only one)
4.UINavigationItem不受 UINavigationBar 控制,更不由 UINavigationController控制,是由當前的視圖控制器控制;
二: toolBar :
PS: 一個UINavigationController 只有一個toolBar,切被當前視圖控制,不受UINavigationController 控制
UIBarButtonItem *addBar = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(button)];
UIBarButtonItem *editBar = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(button )];
UIBarButtonItem *saveBar = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(button )];
UIBarButtonItem *titleBar = [[UIBarButtonItem alloc] initWithTitle:@"titile" style:UIBarButtonItemStyleBordered target:self action:@selector(button)];
//設置間距
UIBarButtonItem *filexBar = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]; //等距離
//自定義間距
UIBarButtonItem *fixBar = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];
fixBar.width = 5;
NSArray *itemArray =@[ addBar, fixBar, editBar,filexBar, saveBar,filexBar, titleBar];
[self.navigationController setToolbarHidden:NO animated:YES];
// [self.navigationController.toolbar setItems:itemArray animated:YES]; // 錯誤寫法,toolBar 只受當前視圖的控制
[self setToolbarItems:itemArray animated:YES];//正確