码迷,mamicode.com
首页 > 其他好文 > 详细

导航控制器

时间:2016-05-13 12:33:41      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:

#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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!