zoukankan      html  css  js  c++  java
  • UINavigationController

    1.创建一个UINavigationController

        self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];   

        FirstViewController * first = [[FirstViewController alloc]init];    

        UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:first];  UINavigationController第一个显示的界面

        self.window.rootViewController = nav;

        [self.window makeKeyAndVisible];

    2.隐藏导航栏工具栏

        self.navigationController.navigationBarHidden = YES;

        self.navigationController.toolbarHidden = NO;

    3.设置导航栏和工具栏的颜色(设置了之后所有都是这个颜色,因为只有一个navigationController)

        self.navigationController.toolbar.barTintColor = [UIColor redColor];

        self.navigationController.navigationBar.barTintColor = [UIColor redColor];

    4.设置左右显示的按钮

        UIBarButtonItem * leftBtn = [[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonItemStyleDone target:nil action:nil];

        self.navigationItem.leftBarButtonItem = leftBtn;

        self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];

        

        UIBarButtonItem * rightBtn = [[UIBarButtonItem alloc]initWithTitle:@"Next" style:UIBarButtonItemStyleDone target:self action:@selector(gotoSecondView)];

        self.navigationItem.rightBarButtonItem = rightBtn;

        self.navigationItem.rightBarButtonItem.tintColor = [UIColor whiteColor];

    5.设置标题

        self.navigationItem.title =@"标题";

        self.navigationBar.titleTextAttributes = @{NSFontAttributeName:[UIFont systemFontOfSize:16],NSForegroundColorAttributeName:[UIColor whiteColor]};

    6.标题位置设置成view

        UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 44)];

        view.backgroundColor = [UIColor yellowColor];

        self.navigationItem.titleView = view;

    7.Next按钮响应第二个界面

    -(void)gotoSecondView{

        SecondViewController * svc = [[SecondViewController alloc]init];

        //设置默认提供的返回按钮的标题

        UIBarButtonItem *backItem = [[UIBarButtonItem allocinitWithTitle:@"返回" style:UIBarButtonItemStyleDone target:nil action:nil];

        self.navigationItem.backBarButtonItem = backItem;

        //present:在现有的界面上盖上一层 dismissViewController来消除

        //[self.navigationController presentViewController:svc animated:YES completion:nil];

        //push:push入栈 pop出栈来消除

        [self.navigationController pushViewController:svc animated:YES];

    }

  • 相关阅读:
    springmvc(8)ajax&json处理
    springmvc(7) 文件上传
    springmvc(6)乱码及restful风格
    springmvc(5)数据的处理
    java面试题复习(八)
    java面试题复习(七)
    java面试题复习(六)
    java面试题复习(五)
    java面试题复习(四)
    java面试题复习(三)
  • 原文地址:https://www.cnblogs.com/huoran1120/p/5168596.html
Copyright © 2011-2022 走看看