UINavigationController & UIBarButtonItem & UIToolbar

//初始化导航控制器
    ViewController *vc=[[ViewController alloc]init];
    UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:vc];
    self.window.rootViewController=nav;

一.导航控制器的基本组成
1.navigationBar   导航栏
2.toolbar         工具栏

二.导航控制器的基本属性和方法

//获取栈中最顶层的视图控制器
self.navigationController.topViewController
//获取栈中当前现实的视图控制器
self.navigationController.visibleViewController
//隐藏导航栏
self.navigationController.navigationBarHidden=YES;
//获取导航栏目
self.navigationController.navigationBar;

//设置导航栏隐藏
[self.navigationController setNavigationBarHidden:YES];
//设置工具栏隐藏
[self.navigationController setToolbarHidden:YES];
//设置标题
[self.navigationController setTitle:@"hello"];
//设置导航栏背景图片
[nav.navigationBar setBackgroundImage:[UIImage imageNamed:@"1.png"] forBarMetrics:UIBarMetricsDefault];

三.导航控制器页面跳转
//    跳转到下一个页面 push方法
    SecondViewController *secondVC = [[SecondViewController alloc] init];

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

//    返回上一页
    [self.navigationController popViewControllerAnimated:YES];

//    回到根视图
    [self.navigationController popToRootViewControllerAnimated:YES];

//返回指定页面
NSArray *array = self.navigationController.viewControllers;
    SecondViewController *secondVC = [array objectAtIndex:1];
    [self.navigationController popToViewController:secondVC animated:YES];

四.导航栏和工具栏
(1)导航栏
1。导航栏添加按钮
//系统样式
    UIBarButtonItem *right=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addNewOne)];
    self.navigationItem.rightBarButtonItem=right;

/*
图片样式
    UIBarButtonItem *right1=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"1.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(addNewOne)];
字样式
    UIBarButtonItem *right=[[UIBarButtonItem alloc]initWithTitle:@"add" style:UIBarButtonItemStyleBordered target:self action:@selector(addNewOne)];
*/
2.设置导航栏
    //设置导航栏的风格
    self.navigationController.navigationBar.barStyle=UIBarStyleBlack;
    //设置导航栏为透明
    self.navigationController.navigationBar.translucent=YES;
    //设置导航栏的颜色
    self.navigationController.navigationBar.tintColor=[UIColor redColor];
    //隐藏导航栏返回按钮
    [self.navigationItem setHidesBackButton:YES];
    //导航栏提示
    [email protected]"hello";
3.定制导航栏
//view为自定义UIView
1.self.navigationItem.titleView=view;

(2)工具栏
1.初始化工具栏
    //初始化toolbar
   UIToolbar *toolbar=[[UIToolbar alloc]initWithFrame:CGRectMake(0, 450, 320, 30)];
    //初始化toolbar上的按钮
    UIBarButtonItem *button1=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(goToNext)];
    //制作间隔(系统默认等宽间隔)
    UIBarButtonItem *fiex=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
/*
    //自定义间隔
    UIBarButtonItem *myfiex=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];
    myfiex.width=30;
*/
    //将按钮放进数组中
    NSArray *array=[[NSArray alloc]initWithObjects:button1 ,fiex,button2,fiex,button3, nil];
    //将数组的按钮添加到toolbar中
    [toolbar setItems:array animated:YES];
    //将toolbar添加到view中
    [self.view addSubview:toolbar];

五.导航控制器部件大小
状态栏 20px;
导航栏 44/32px;
工具栏 44/32px;
导航栏按钮  20*20;

时间: 2024-08-07 17:40:21

UINavigationController & UIBarButtonItem & UIToolbar的相关文章

Add sharing to your app via UIActivityViewController

http://www.codingexplorer.com/add-sharing-to-your-app-via-uiactivityviewcontroller/ April 4, 2014 Ever wonder what various apps like Photos or Safari use when you click on the share button? So did I until a few days ago. It is apparently UIActivityVi

UI--普通控件总结1--控件使用

本文目录 0.UIView常用的属性和操作 0_1.UIView常见的属性 0_2.UIView状态 0_3.UIView常用的方法 1.文本框UITextField和文本视图UITextView 1_1.文本框UITextField(几乎包含了iOS控件的所有的通用属性) 1_2.文本视图UITextView 1_3.键盘输入的处理程序 2.标签UILabel和按钮UIButton 2_1.标签UILabel 2_2.按钮UIButton 3.滑块UISlider.步进UIStepper和图像

iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem

转自:http://blog.csdn.net/totogo2010/article/details/7681879 1.UINavigationController导航控制器如何使用 UINavigationController可以翻译为导航控制器,在iOS里经常用到. 我们看看它的如何使用: 下面的图显示了导航控制器的流程.最左侧是根视图,当用户点击其中的General项时 ,General视图会滑入屏幕:当用户继续点击Auto-Lock项时,Auto-Lock视图将滑入屏幕.相应地,在对象

UINavigationController和UIBarButtonItem的例子

#import "AppDelegate.h" #import "FirstViewController.h" #import "SecondViewController.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOption

UITabBarController+UINavigationController+UIToolBar

一,各种名称和位置 //技巧一键换肤    [[UINavigationBar appearance]setBarTintColor:[UIColor redColor]];//给所有的NavigationBar换颜色    [[UITabBar appearance]setBarTintColor:[UIColor blueColor]];//给所有的TabBar换颜色 二,UINavigationBar: 1,设置导航条透明度:self.navigationBar.translucent =

iOS 开发 中级:UIToolbar,UINavigationBar,UITabBar,UIBarButtonItem,UITabBarItem自定义方法总结

原文:  http://blog.csdn.net/songrotek/article/details/8692866?utm_source=tuicool 对于UIToolbar,UINavigationBar,UITabBar,UIBarButtonItem,UITabBarItem这几种控件的自定义,因为具备共同性,因此放在一起讨论. 通常有两种方式来实现自定义. 1)获取控件的对象,然后对这个特定的对象进行特定的修改. 2)利用UIAppearance来实现对所有同类控件及特定同类的自定

iOS开发 OC 导航栏 UINavigationController 工具条 UIToolBar

导航栏最常见的例子就是返回按钮的所在 在AppDelegate.m中,代码布局最开始定义窗口的时候, _window.rootViewController就应该为一个UINavigationController 这里的UINavigationController,戳进定义发现它是UIViewcontroller的子类 而之前代码布局中这里用的rootController是UIViewcontroller 所以它之中也是像之前代码布局中的UIViewcontroller一样是包含多个control

iOS: 工具栏控件UIToolBar和工具栏按钮控件UIBarButtonItem的使用

一.工具栏控件:UIToolBar:UIView 介绍: ToolBar工具栏是视图View的属性,可以在工具栏上添加工具栏按钮Bar Button Item(可以是自定义的Custom.也可以是系统自带的BarButtonSystemItem ),视图控制器可以通过工具栏项对视图中内容进行操作. 注意事项: 在导航栏控制器中会有一个UIToolBar实例,但默认是隐藏的,如果需要显示,需要通过这个方法将其打开: 在这里需要注意的是,与UINavigationBar类似,导航控制器拥有且只拥有一

[转]iOS学习之UINavigationController详解与使用(一)添加UIBarButtonItem

转载地址:http://blog.csdn.net/totogo2010/article/details/7681879 1.UINavigationController导航控制器如何使用 UINavigationController可以翻译为导航控制器,在iOS里经常用到. 我们看看它的如何使用: 下面的图显示了导航控制器的流程.最左侧是根视图,当用户点击其中的General项时 ,General视图会滑入屏幕:当用户继续点击Auto-Lock项时,Auto-Lock视图将滑入屏幕.相应地,在