一,效果图。

二,工程图。

三,代码

RootViewController.h

#import <UIKit/UIKit.h>

@interface RootViewController : UIViewController
{
UIButton * leftButton;
UIButton * rightButton;
UIViewController * firstController;
UIViewController * secondController; }
@end

RootViewController.m

#import "RootViewController.h"

@interface RootViewController ()

@end

@implementation RootViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
} - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view. //初始化顶部按钮
[self creatHeadView]; //初始化背景图
[self initBackView]; }
#pragma -mark -functions
//初始化背景图
-(void)initBackView
{
firstController = [[UIViewController alloc] init];
firstController.view.backgroundColor = [UIColor redColor];
[self.view addSubview:firstController.view]; secondController = [[UIViewController alloc] init];
secondController.view.backgroundColor = [UIColor blueColor]; }
//初始化顶部按钮
-(void)creatHeadView
{
UIView * headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 30)]; //左边的按钮
leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
leftButton.frame = CGRectMake(0, 0, 50, 30);
leftButton.tag = 201;
leftButton.enabled = NO;
[leftButton setImage:[UIImage imageNamed:@"left"] forState:UIControlStateNormal];
[leftButton addTarget:self action:@selector(doClickHeadActions:) forControlEvents:UIControlEventTouchUpInside];
[headView addSubview:leftButton]; //右边的按钮
rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
rightButton.frame = CGRectMake(50, 0, 50, 30);
rightButton.tag = 301;
[rightButton setImage:[UIImage imageNamed:@"right"] forState:UIControlStateNormal];
[rightButton addTarget:self action:@selector(doClickHeadActions:) forControlEvents:UIControlEventTouchUpInside];
[headView addSubview:rightButton]; self.navigationItem.titleView = headView; }
#pragma -mark -doClickActions
-(void)doClickHeadActions:(UIButton *)btn
{
if (btn.tag == 201)
{
[secondController dismissViewControllerAnimated:NO completion:nil];
[self.view addSubview:firstController.view]; [btn setImage:[UIImage imageNamed:@"leftselect"] forState:UIControlStateNormal];
btn.enabled = NO;
[rightButton setImage:[UIImage imageNamed:@"right"] forState:UIControlStateNormal];
rightButton.enabled = YES;
}
else if (btn.tag == 301)
{
[firstController dismissViewControllerAnimated:NO completion:nil];
[self.view addSubview:secondController.view]; [btn setImage:[UIImage imageNamed:@"rightselect"] forState:UIControlStateNormal];
btn.enabled = NO;
[leftButton setImage:[UIImage imageNamed:@"left"] forState:UIControlStateNormal];
leftButton.enabled = YES;
} }
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

【代码笔记】iOS-标题2个图标,点击的时候,页面跳转的更多相关文章

  1. iOS 极光推送 如何点击推送消息跳转页面

    假如你已经集成完了极光,恰好有这个问题不知如何解决,可以看看这篇文章,这篇是针对远程通知的,本地通知大同小异吧. 根据我项目的要求,极光推送跳转指定页面分为两种情况:app在后台情况和app在杀死的情 ...

  2. 【代码笔记】iOS-UITableView上的button点击事件

    代码. ViewController.h #import <UIKit/UIKit.h> @interface ViewController : UIViewController < ...

  3. 【代码笔记】iOS-4个可以单独点击的button

    一,效果图. 二,工程图. 三,代码. ViewController.m #import "ViewController.h" @interface ViewController ...

  4. IOS开发笔记 IOS如何访问通讯录

    IOS开发笔记  IOS如何访问通讯录 其实我是反对这类的需求,你说你读我的隐私,我肯定不愿意的. 幸好ios6.0 以后给了个权限控制.当打开app的时候你可以选择拒绝. 实现方法: [plain] ...

  5. IOS APP的所有图标尺寸规范

    转自: http://blog.csdn.net/chonbj/article/details/25133247 像我一样记不住iOS应用图标像素尺寸的开发者不在少数,我经常需要查询不同设备上的应用尺 ...

  6. 【hadoop代码笔记】Mapreduce shuffle过程之Map输出过程

    一.概要描述 shuffle是MapReduce的一个核心过程,因此没有在前面的MapReduce作业提交的过程中描述,而是单独拿出来比较详细的描述. 根据官方的流程图示如下: 本篇文章中只是想尝试从 ...

  7. 【hadoop代码笔记】hadoop作业提交之汇总

    一.概述 在本篇博文中,试图通过代码了解hadoop job执行的整个流程.即用户提交的mapreduce的jar文件.输入提交到hadoop的集群,并在集群中运行.重点在代码的角度描述整个流程,有些 ...

  8. 【Hadoop代码笔记】目录

    整理09年时候做的Hadoop的代码笔记. 开始. [Hadoop代码笔记]Hadoop作业提交之客户端作业提交 [Hadoop代码笔记]通过JobClient对Jobtracker的调用看详细了解H ...

  9. 笔记-iOS 视图控制器转场详解(上)

    这是一篇长文,详细讲解了视图控制器转场的方方面面,配有详细的示意图和代码,为了使得文章在微信公众号中易于阅读,seedante 辛苦将大量长篇代码用截图的方式呈现,另外作者也在 Github 上附上了 ...

  10. <Python Text Processing with NLTK 2.0 Cookbook>代码笔记

    如下是<Python Text Processing with NLTK 2.0 Cookbook>一书部分章节的代码笔记. Tokenizing text into sentences ...

随机推荐

  1. ASP.NET MVC动态生成网站菜单及子菜单

    在开发ASP.NET MVC网站时,Insus.NET想实现动态产生网站的主菜单及子菜单. 你需要在网站管理后台管理此2张表(Menu,SubMenu)的信息,添加,删除,编辑,更新等. Sequen ...

  2. Java动态程序设计:反射介绍

    使用运行的类的信息使你的程序设计更加灵活 反射授予了你的代码访问装载进JVM内的Java类的内部信息的权限,并且允许你编写在程序执行期间与所选择的类的一同工作的代码,而不是在源代码中.这种机制使得反射 ...

  3. 一个故事讲清楚NIO

    转载请引用:一个故事讲清楚NIO 假设某银行只有10个职员.该银行的业务流程分为以下4个步骤: 1) 顾客填申请表(5分钟): 2) 职员审核(1分钟): 3) 职员叫保安去金库取钱(3分钟): 4) ...

  4. Nancy 自定义JsonSerializer

    1.创建自己的jsonserializer类 public class CustomJsonNetSerializer : JsonSerializer, ISerializer { public C ...

  5. WCF在编译出现 “错误 3 命令“时解决

    如果你遇到了下面问题解决方案很简单,以管理员身份运行VS就OK了. 错误 3 命令“ mkdir %SystemDrive%\inetpub\wwwroot\servicemodelsamples m ...

  6. .net5的异步

    public static class TaskAsyncHelper { /// <summary> /// 将一个方法function异步运行,在执行完毕时执行回调callback / ...

  7. css3渐变(Gradients)

    <html> http://www.runoob.com/css3/css3-gradients.html CSS3 渐变(gradients)可以让你在两个或多个指定的颜色之间显示平稳的 ...

  8. Eclipse导入Java项目时“No projects are found to import”错误的处理

    用Eclipse导入Java项目时,经常会出现“No projects are found to import”错误(尤其是导入网上下载的项目时),这是因为文件夹里面没有.project和.class ...

  9. archive for required library...

    最近把移动硬盘上的一个Android项目复制到笔记本上面,import后项目文件夹始终有一个红色叹号,console里面提示“archive for required library...”,原来是l ...

  10. 基于TCP和多线程实现无线鼠标键盘-GestureDetector

    为了实现无线鼠标,需要识别出用户在手机屏幕上的滑动动作,这就需要用到GestureDetector类. 首先是activity_main.xml: <LinearLayout xmlns:and ...