zoukankan      html  css  js  c++  java
  • UI控件之UINavigationController

    ViewController1 *vc1=[[ViewController1 alloc]init];

    UINavigationController *nav1=[[UINavigationController alloc]initWithRootViewController:vc1];

    自动设置导航栏上的标题,自动设置标签栏项上的标题为此值

    vc1.title=@"界面1";

    设置导航栏上的标题

    vc1.navigationItem.title=@"jiemian1";

    设置标签栏项上的标题

    nav1.tabBarItem.title=@"界面1";

    设置标签栏项上的图片

    UIImage *img0=[UIImage imageNamed:@"tab_0.png"];

    img0=[img0 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    nav1.tabBarItem.image=img0;

    设置徽标

    vc1.tabBarItem.badgeValue=@"2";

    UINavigationController:导航控制器

    父类是IViewController,容器控制器,采用栈的方式对视图控制器进行管理,视图控制器通过出栈、入栈进行切换一般用于复杂的分层数据结构维护一个栈容器,任意类型的视图控制器对象都可以添加到其中

    RootViewController *root=[[RootViewController alloc]init];

    实例化导航控制器时需提供一个视图控制器对象,作为其根视图控制器,当程序启动时自动将根视图控制器对象的view加载到window上

    UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:root];

    self.window.rootViewController=nav;

    实例化第2个视图控制器对象

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

    self.navigationController获取管理它的导航控制器对象,前提条件是self已经添加到导航控制器对象中将second压入到栈容器的栈顶,切换视图,第2个参数是是否有动画效果

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

    将栈顶元素(视图控制器对象)出栈,第2个参数设置动画效果

    [self.navigationController popViewControllerAnimated:YES];

    将栈底以上所有的视图控制器对象出栈(返回到根视图控制器界面)

    [self.navigationController popToRootViewControllerAnimated:YES];

    获取导航控制器对象管理的所有的视图控制器对象,它们在数组中的顺序与在栈容器中的顺序一致

    NSArray *array= self.navigationController.viewControllers;

    直接返回到某个视图控制器对象(会将该视图控制器对象上面的都从栈容器中移除)

    [self.navigationController popToViewController:array[1] animated:YES];

    导航控制器只有一个导航栏,所有被导航控制器管理的视图控制器共用一个导航栏

    设置navigationBar的样式,有4个取值,只有2种效果

    self.navigationController.navigationBar.barStyle=UIBarStyleDefault;

    设置navigationBar的背景色

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

    iOS6.0后用barTintColor属性可以设置navigationBar的背景色

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

    iOS6.0后用tintColor属性设置navigationBar上的字体颜色

    self.navigationController.navigationBar.tintColor=[UIColor yellowColor];

    设置navigationBar的背景图片,如果图片高度是44像素,状态栏会显示为黑色,否则状态栏也会用图片填充

    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navBg.png"] forBarMetrics:UIBarMetricsDefault];第2个参数是设置什么模式下有背景图片,UIBarMetricsCompact肖像模式下没有背景图片,风景模式下有UIBarMetricsDefault:肖像和风景模式下都有背景图片

    设置是否需要裁减背景图片(状态栏是否也有背景图片)

    self.navigationController.navigationBar.clipsToBounds=YES;

    设置是否隐藏navigationBar

    self.navigationController.navigationBarHidden=YES;

    设置隐藏时是否带有动画效果

    [self.navigationController setNavigationBarHidden:YES animated:YES];

    设置navigationBar为隐藏状态,默认为显示

    self.navigationController.navigationBarHidden=YES;

    iOS7.0中push到导航控制器中,如果view的背景色为clearColor,push时会有卡顿的现象,解决办法就是设置push的背景色

    self.view.backgroundColor=[UIColor whiteColor];

    每个视图控制器需要单独设计自己navigationBar上的navigationItem

    设置navigationBar上的标题,居中显示

    当从下一个视图控制器返回时其左侧按钮上显示的是该标题,如果该标题过长,会显示"Back"而非标题

    self.navigationItem.title=@"Root";

    设置视图控制器的标题(自动将navigationBar上标题也设置为此值)

    self.title=@"Home";

    UIImage *image1=[UIImage imageNamed:@"itemImage.png"];

    设置图片的渲染模式:使用原始样式显示,不渲染

    image1=[image1 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    设置navigationBar的左侧按钮(一个)

    self.navigationItem.leftBarButtonItem=item1;

    一个导航控制器只有一个toolBar,被导航控制器管理的视图控制器共有一个toolBar

    将toolBar显示,默认是隐藏的,高度44

    self.navigationController.toolbarHidden=NO;

    UIBarButtonItem *item1=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:nil action:nil];

    UIBarButtonItem *item2=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemPause target:nil action:nil];

    UIBarButtonItem *item3=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

    NSArray *array=@[item3, item1,item3,item2,item3];

    设置当前视图控制器的toolbar上的项

    self.toolbarItems=array;

    http://www.cnblogs.com/PaulpauL/ 版权声明:本文为博主原创文章,未经博主允许不得转载。
  • 相关阅读:
    eclipse中Preferences的一些设置
    eclipse中文乱码问题解决方案
    classpath、path、JAVA_HOME的作用
    java中抽象类与接口中方法访问修饰符问题 (
    Tomcat配置
    编译型语言和解释型语言
    强类型语言和弱类型语言
    javascript生成指定范围的随机整数
    java中int和Integer的区别
    红黑树入门
  • 原文地址:https://www.cnblogs.com/PaulpauL/p/4890091.html
Copyright © 2011-2022 走看看