标签:
#import "ViewController.h"
#import "DetailViewController.h"
@interface ViewController ()
#define RED arc4random() % 255 / 255.0
#define GREEN arc4random() % 255 / 255.0
#define BLUE arc4random() % 255 / 255.0
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor colorWithRed:RED green:GREEN blue:BLUE alpha:1.0];
//设置navigationBarHidden 导航栏的隐藏
self.navigationController.navigationBarHidden = NO;
//设置导航栏颜色 navigationBar
self.navigationController.navigationBar.barTintColor = [UIColor orangeColor];
//设置标题
self.title = @"首页";
//设置导航栏主色调
self.navigationController.navigationBar.tintColor = [UIColor greenColor];
//创建item
UIBarButtonItem * leftItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(action_button:)];
leftItem.tag = 100;
//关联
self.navigationItem.rightBarButtonItem = leftItem;
//创建弹性item
UIBarButtonItem *flexItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *toolBarItem1 = [[UIBarButtonItem alloc] initWithTitle:@"下一页" style:UIBarButtonItemStylePlain target:self action:nil];
UIBarButtonItem *toolBarItem2 = [[UIBarButtonItem alloc] initWithTitle:@"上一页" style:UIBarButtonItemStylePlain target:self action:nil];
//导航工具栏 默认隐藏的
self.navigationController.toolbarHidden = NO;
self.toolbarItems = @[flexItem, toolBarItem1,flexItem,toolBarItem2,flexItem];
//创建一个button
UIButton *button =[UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, 200, 30);
button.center = self.view.center;
[button setTitle:@"导航推送" forState:UIControlStateNormal];
button.tag = 101;
[button addTarget:self action:@selector(action_button:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
- (void)action_button:(id)sender {
if ([sender isKindOfClass:[UIBarButtonItem class]]) {
// //直接返回到根视图控制器
// [self.navigationController popToRootViewControllerAnimated:YES];
//返回到上一个视图控制器
[self.navigationController popViewControllerAnimated:YES];
//返回到指定控制器, 该控制器必须已经被navigationController所管理
// [self.navigationController popToViewController:self.navigationController.viewControllers[0] animated:YES];
return;
}
DetailViewController *viewController = [[DetailViewController alloc] init];
// viewController.view.backgroundColor = [UIColor orangeColor];
//导航推送
[self.navigationController pushViewController:viewController animated:YES];
}
#import "DetailViewController.h"
@interface DetailViewController ()
@end
@implementation DetailViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title = @"详情";
self.view.backgroundColor = [UIColor redColor];
// self.navigationController.viewControllers[0]
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
标签:
原文地址:http://www.cnblogs.com/wtzs/p/5487051.html