self.navigationItem.title=@"顯示工具欄"; // 顯示工具欄 //self.navigationController.toolbarHidden = NO; [self.navigationController setToolbarHidden:NO]; //設置 toolbar的背景圖片, 參數:背景圖,什麼位置顯示(),什麼模式顯示(橫屏,豎屏) //[self.navigationController.toolbar setBackgroundImage:[UIImage imageNamed:@"1.jpg"] forToolbarPosition:UIToolbarPositionBottom barMetrics:UIBarMetricsDefault]; self.navigationController.toolbar.frame = CGRectMake(0, 0, 320, 44); //通過toolbaritems來設置工具欄的顯示項,數組中是UIBarButtonItem的實例 UIBarButtonItem *item1 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:nil]; UIBarButtonItem *item2 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:nil]; //item 的間隔,不會顯示出來,會自動計算間隔 UIBarButtonItem *spaceItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]; NSArray *items = [NSArray arrayWithObjects:spaceItem, item1,spaceItem,item2,spaceItem, nil]; self.toolbarItems = items;
上述代碼出來效果: