导航栏标题、颜色、按钮文字、文字颜色、样式、导航栏上按钮样式等的设置
先创建名为 OneViewController、TwoViewController、ThreeViewController的视图控制器,并设置其导航栏标题及背景颜色以作页面切换时的区分
//导航栏上显示的标题
self.navigationItem.title = @"stupid";
//默认导航栏是YES透明的,NO不透明
self.navigationController.navigationBar.translucent = YES;
//导航栏上按钮颜色
self.navigationController.navigationBar.tintColor = [UIColor redColor];
//导航栏样式
self.navigationController.navigationBar.barStyle = UIBarStyleDefault;
//导航栏颜色
self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:50.0/255.0f green:250.0/255.0f blue:120.0/255.0f alpha:1.0];
//导航栏上还有navigationItem ,initWithBarButtonSystemItem初始化按钮样式
UIBarButtonItem *left = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemRewind target:self action:@selector(leftAction:)];
//把按钮left设置为navigationItem的左边按钮
self.navigationItem.leftBarButtonItem = left;
//使用自定义视图设置button
UIButton *rightbt = [UIButton buttonWithType:UIButtonTypeCustom];
rightbt.frame = CGRectMake(0, 0, 44, 44);
[rightbt setTitle:@"next" forState:UIControlStateNormal];
[rightbt setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[rightbt addTarget:self action:@selector(rightAction:) forControlEvents:UIControlEventTouchUpInside];
//把创建的按钮设置为UIBarButtonItem初始化时的自定义视图
UIBarButtonItem *rightBarbt = [[UIBarButtonItem alloc]initWithCustomView:rightbt];
//把rightBarbt设置为navigationItem右侧按钮
self.navigationItem.rightBarButtonItem = rightBarbt;
- (void)leftAction:(UIBarButtonItem *)bar{
ThreeViewController *three = [[ThreeViewController alloc]init];
[self.navigationController pushViewController:three animated:YES];
}
属性传值:
第一步:在TwoViewController.h中设置一个字符串类型的属性
@property(nonatomic,retain)NSString *str;
第二步:把导航栏的标题设置为self.str
self.navigationItem.title = self.str;
- (void)rightAction:(UIBarButtonItem *)bar{
TwoViewController *two = [[TwoViewController alloc]init];
第三步:等号两边内容一致才能完成属性传值
two.str = self.tf.text;
[self.navigationController pushViewController:two animated:YES];
}