/*下面是UINavigationBar*/
//创建一个导航栏
UINavigationBar *navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];
//把导航栏添加到视图中
[self.view addSubview:navigationBar];
//创建一个导航栏集合
UINavigationItem *navigationItem = [[UINavigationItem alloc] init];
//创建一个左边按钮
UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:@"左边" style:UIBarButtonItemStyleBordered target:self action:@selector(clickLeftButton)];
//创建一个右边按钮
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"右边" style:UIBarButtonItemStyleDone target:self action:@selector(clickRightButton)];
//把左右两个按钮添加入导航栏集合中
[navigationItem setLeftBarButtonItem:leftButton];
[navigationItem setRightBarButtonItem:rightButton];
//设置导航栏内容
[navigationItem setTitle:@"标题"];
//把导航栏集合添加入导航栏中,设置动画关闭
[navigationBar pushNavigationItem:navigationItem animated:NO];
//如果碰到是UINavigationController要添加一个按钮的话
UINavigationController *nav;
nav.rightBarButtonItem = xxx;
nav.leftBarButtonItem = xxx;
/****************************************/
/*下面是UIToolbar*/
//标题栏
UIToolbar * aToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, [UIScreen mainScreen].applicationFrame.size.height-44, 320, 44)];
aToolbar.tintColor = [UIColor blackColor];
[self.view addSubview:aToolbar];
//返回
UIBarButtonItem * backItem = [[UIBarButtonItem alloc] initWithTitle:@"返回"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(backUpPage:)];
backItem.tintColor = [UIColor grayColor];
//标题
UIBarButtonItem * titleItem = [[UIBarButtonItem alloc] initWithTitle:@"选择城市"
style:UIBarButtonItemStylePlain
target:nil
action:nil];
//确定按钮
UIBarButtonItem * confirmItem = [[UIBarButtonItem alloc] initWithTitle:@"确定"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(confirmSelectCity:)];
confirmItem.tintColor=[UIColor grayColor];
//站位Item
UIBarButtonItem * spaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil];
aToolbar.items = [NSArray arrayWithObjects:backItem, spaceItem, titleItem, spaceItem,confirmItem, nil];