UIBarbuttonItem

APPDelegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

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

    //创建主界面,导航栏的第一个页面

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

    

    //创建一个导航栏控制器

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

    nav.navigationBar.barTintColor = [UIColor redColor];

    self.window.rootViewController = nav;//设置根控制器

    [self.window makeKeyAndVisible];

    return YES;

}

 

//给导航栏添加左右按钮

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

    self.navigationItem.leftBarButtonItem = cancelButton;

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

    

    UIBarButtonItem *nextButton = [[UIBarButtonItem alloc]initWithTitle:@"next" style:UIBarButtonItemStyleDone target:self action:@selector(goToSecond)];

    self.navigationItem.rightBarButtonItem = nextButton ;

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

    

    UILabel *yLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 44)];

    yLabel.backgroundColor = [UIColor yellowColor];

    yLabel.text = @"新浪";

    yLabel.font = [UIFont systemFontOfSize:22];

    yLabel.textColor = [UIColor redColor];

    yLabel.textAlignment = NSTextAlignmentCenter;

    self.navigationItem.titleView = yLabel;

-(void)goToSecond{

    //创建即将显示的界面

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

    //使用导航栏控制器切换页面

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

    //push入栈 将当前的界面入栈,这个界面消失,将新的界面推送出来

    //pop 将当前的界面消失,从栈上最上面的界面(最后一个界面)出栈

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

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

    self.navigationItem.backBarButtonItem = backItem;  

    [self.navigationController showViewController:svc sender:self];

}

 

-(void)viewWillAppear:(BOOL)animated{

    [super viewWillAppear:animated];

    //显示工具栏

    self.navigationController.toolbarHidden = NO;

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

    //默认工具栏高44,导航栏高44

    //可以隐藏导航栏

//    self.navigationController.navigationBarHidden = YES;

}

 SecondViewController类.m

-(void)viewDidLoad{

    [super viewDidLoad];

    UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];

    [btn setTitle:@"back" forState:UIControlStateNormal];

    btn.frame = CGRectMake(100, 200, 120, 50);

    [btn addTarget:self action:@selector(goback) forControlEvents:UIControlEventTouchUpInside];

    btn.tintColor = [UIColor whiteColor];

    [self.view addSubview:btn];

}

-(void)goback{

     //present 在现有的界面上盖上一层,dismissViewController删除

    //如果之前使用 的push 那么用pop

    [self.navigationController popViewControllerAnimated:YES];

    [self dismissViewControllerAnimated:YES completion:nil];

}

 

拓:navigationbar 上加多个button:

UIView *rightBarView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 60, 31)];UIButton *phonebutton = [UIButton buttonWithType:UIButtonTypeCustom];phonebutton.frame=CGRectMake(0, 5, 25, 25);[phonebutton setImage:[UIImage imageNamed:@"phone.png"] forState:UIControlStateNormal];[phonebutton addTarget:self action:@selector(phoneclick)forControlEvents:UIControlEventTouchDown];[rightBarView addSubview:phonebutton];UIButton *mapbutton = [UIButton buttonWithType:UIButtonTypeCustom];[mapbutton setFrame:CGRectMake(30, 5, 25, 25)];[mapbutton setImage:[UIImage imageNamed:@"c_address.png"] forState:UIControlStateNormal];[mapbutton addTarget:self action:@selector(mapclick)forControlEvents:UIControlEventTouchDown];[rightBarView addSubview:phonebutton];[rightBarView addSubview:mapbutton];rightBarView.backgroundColor=[UIColor clearColor];UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc]initWithCustomView:rightBarView];self.navigationItem.rightBarButtonItem = rightBtn;

 更简便的方法:

转载于:https://www.cnblogs.com/yangqinglong/p/5363708.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/458101.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

深度残差网络ResNet解析

ResNet在2015年被提出,在ImageNet比赛classification任务上获得第一名,因为它“简单与实用”并存,之后很多方法都建立在ResNet50或者ResNet101的基础上完成的,检测,分割,识别等领域都纷纷使用ResNet&#x…

Oracle-一个中文汉字占几个字节?

Oracle 一个中文汉字占用几个字节 Oracle 一个中文汉字 占用几个字节,要根据Oracle中字符集编码决定!!! 1. 如果定义为VARCHAR2(32 CHAR),那么该列最多就可以存储32个汉字,如果定义字段为VARCHAR2(32) 或VARCHAR2(32 B…

基于深度学习的目标检测技术演进:R-CNN、Fast R-CNN、Faster R-CNN

object detection我的理解,就是在给定的图片中精确找到物体所在位置,并标注出物体的类别。object detection要解决的问题就是物体在哪里,是什么这整个流程的问题。然而,这个问题可不是那么容易解决的,物体的尺寸变化范…

iPhone屏幕尺寸/launch尺寸/icon尺寸

屏幕尺寸 6p/6sp 414 X 7366/6s 375 X 6675/5s 320 X 568 4/4s 320 X 480launch尺寸 6p/6sp 1242 X 2208 3x6/6s 750 X 1334 2x5/5s 640 X 1136 2x4/4s 640 X 960 2x仔细观察会发现l…

CNN的发展历史(LeNet,Alexnet,VGGNet,GoogleNet,ReSNet)

欢迎转载,转载请注明:本文出自Bin的专栏blog.csdn.net/xbinworld。 关于卷积神经网络CNN,网络和文献中有非常多的资料,我在工作/研究中也用了好一段时间各种常见的model了,就想着简单整理一下,以备查阅之需…

读取csv格式的数据

1.直接上代码&#xff0c;关键是会用 2.代码如下&#xff1a; <?php #添加推荐到英文站 $file fopen(code.csv,r); while ($data fgetcsv($file)) { //每次读取CSV里面的一行内容 //print_r($data); //此为一个数组&#xff0c;要获得每一个数据&#xff0c;访问数组下…

如何在VMWare的Ubuntu虚拟机中设置共享文件夹

亲测有效&#xff1a;Ubuntu18.04 LTS、虚拟机VMware Workstation 14 Pro 14.1.3 build-9474260、Window7 自己的第一篇博文&#xff0c;由于时&#xff08;shuǐ&#xff09;间&#xff08;png&#xff09;原&#xff08;yǒu&#xff09;因&#xff08;xin&#xff09;&…

容器+AOP实现动态部署(四)

上篇咱们介绍了容器和AOP的结合&#xff0c;结合后怎样将对象增强服务并没有过多的说明&#xff0c;这里将详细说明怎样将对象 进行增强 &#xff0c;达到一个一对多和多对多的增强方式 先从简单的方式说起 /** *JDK代理类&#xff0c;实现动态调用对象方法 */ public class JD…

caffe专题五——回归中——检测框架

https://blog.csdn.net/runner668/article/details/80436850

深入理解卷积层,全连接层的作用意义

有部分内容是转载的知乎的&#xff0c;如有侵权&#xff0c;请告知&#xff0c;删除便是&#xff0c;但由于是总结的&#xff0c;所以不一一列出原作者是who。 再次感谢&#xff0c;也希望给其他小白受益。 首先说明&#xff1a;可以不用全连接层的。 理解1&#xff1a; 卷…

用ionic快速开发hybird App(已附源码,在下面+总结见解)

用ionic快速开发hybird App&#xff08;已附源码,在下面总结见解&#xff09; 1.ionic简介 ionic 是用于敏捷开发APP的解决方案。核心思路是&#xff1a;利用成熟的前端开发技术&#xff0c;来写UI和业务逻辑。也就是说&#xff0c;就是一个H5网站&#xff0c;这个区别于react-…

为什么要使用工厂模式

工厂的作用相当于帮助我们完成实例化的操作。 优势1&#xff1a;一般在代码中&#xff0c;实例化一个类A是直接new A&#xff08;&#xff09;&#xff0c;假如类A是一个完全独立的类&#xff0c;没有相似类&#xff0c;则没有必要使用工厂模式&#xff0c;直接new A&#xff…

css各兼容应该注意的问题

1.div布局在ie浏览器和chrome浏览器&#xff0c;firefox浏览器不同&#xff0c;不如在div里面嵌套3个div&#xff0c;分别左中右&#xff0c;左边div的pading和margin在ie8以上都是几乎相同&#xff0c;ie8以下做内边距x2&#xff0c;在中间的div在chrome和fierfox中默认在左边…

转 C++宏定义详解

来自&#xff1a;传送门 C宏定义详解 一、#define的基本用法 #define是C语言中提供的宏定义命令&#xff0c;其主要目的是为程序员在编程时提供一定的方便&#xff0c;并能在一定程度上提高程序的运行效率&#xff0c;但学生在学习时往往不能 理解该命令的本质&#xff0c;总是…

acm之vim的基本配置

http://www.kuangbin.net/archives/vim-acmicpc 转载于:https://www.cnblogs.com/akrusher/articles/5402426.html

40 个重要的 HTML5 面试问题及答案

2019独角兽企业重金招聘Python工程师标准>>> 介绍 我是一个ASP.NET MVC开发人员。最近当我找工作的时候&#xff0c;我发现很多问题都是围绕HTML 5和它的新功能展开的。所以&#xff0c;下面我将列出40个有助于你提高相关HTML 5知识的重要问题。 这些问题并不能保证…

Java常见Jar包的用途

jar包 用途 axis.jar SOAP引擎包 commons-discovery-0.2.jar 用来发现、查找和实现可插入式接口&#xff0c;提供一些一般类实例化、单件的生命周期管理的常用方法. jaxrpc.jar Axis运行所需要的组件包 saaj.jar 创建到端点的点到点连接的方法、创建并处理SOAP消息和附件的方法…

车流检测之halcon光流法算法实现

* This example program shows how to use optical_flow_mg to compute the optical flow in an image sequence and how to segment the optical flow. *这个示例程序显示了如何使用._flow_mg来计算图像序列中的光流&#xff0c;以及如何分割光流。 dev_update_off () dev_…

利用光学流跟踪关键点---30

原创博客:转载请标明出处:http://www.cnblogs.com/zxouxuewei/ 关键点&#xff1a;是多个方向上亮度变化强的区域。 opencv:版本是2.4. 光学流函数&#xff1a;calcOpticalFlowPyrLK()。&#xff08;关键点侦测器使用goodFeaturesToTrack()&#xff09;二者结合。 相应的启动文…