ios基础篇(十一)——UINavgationController的使用(二)页面切换
上篇说到了添加UIBarButtonItem,接下来说说界面切换;
1、首先我们在刚才的RootViewController中添加一个按钮用来实现跳转:
打开RootViewController.m(我就继续写了),添加一个跳转button:

效果图:

2、button动作实现,新建一个NewViewController继承自UIViewController;用pushViewController到navigationController中去;

#import "NewViewController.h"
- (void)nextAction{
NewViewController *NewVC = [[NewViewController alloc] init];
[self.navigationController pushViewController:NewVC animated:YES];
NewVC.title = @"NewViewController";
}
点击button,如图Back为系统自带按钮;

如果不想使用系统自带按钮,我们可以自定义按钮:
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"返回"style:UIBarButtonItemStyleDone target:nil action:nil];
self.navigationItem.backBarButtonItem = backButton;
如图:

3、title的自定义:
#import "NewViewController.h"
@interface NewViewController ()
@end
@implementation NewViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
UILabel *title = [[UILabel alloc] init];
title.text = @"标题";
title.font = [UIFont systemFontOfSize:];
[title sizeToFit];
self.navigationItem.titleView = title;
}
效果图:

4、如果想放置多个按钮:
SegmentedControl又被称作分段控制器,可以一下放置多个按钮又不影响美观:
NSArray *colorArray = @[@"黑", @"白", @"灰"];
UISegmentedControl *segmentCtrl = [[UISegmentedControl alloc] initWithItems:colorArray];
segmentCtrl.selectedSegmentIndex = ;
segmentCtrl.tintColor = [UIColor redColor];
self.navigationItem.titleView = segmentCtrl;
效果图:

添加点击响应事件:
[segmentCtrl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
- (void)segmentAction:(id)segment{
switch ([segment selectedSegmentIndex]) {
case :
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您选择了颜色黑" delegate:self cancelButtonTitle:@"是" otherButtonTitles:@"否", nil];
[alert show];
}
break;
case :
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您选择了颜色白" delegate:self cancelButtonTitle:@"是" otherButtonTitles:@"否", nil];
[alert show];
}
break;
case :
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"您选择了颜色灰" delegate:self cancelButtonTitle:@"是" otherButtonTitles:@"否", nil];
[alert show];
}
break;
default:
break;
}
}
效果图:



ios基础篇(十一)——UINavgationController的使用(二)页面切换的更多相关文章
- ios基础篇(二十一)—— UIImagePickerController类
UIImagePickerController简述: UIImagePickerController 类是获取选择图片和视频的用户接口,我们可以用UIImagePickerController选择我们 ...
- ios基础篇(十二)——UINavgationController的使用(三)ToolBar
UIToolBar存在于UINavigationController导航栏控制器中,而且默认被隐藏:设置UINavigationController的toolbarHidden属性可显示UIToolB ...
- ios基础篇(二十九)—— 多线程(Thread、Cocoa operations和GCD)
一.进程与线程 1.进程 进程是指在系统中正在运行的一个应用程序,每个进程之间是独立的,每个进程均运行在其专用且受保护的内存空间内: 如果我们把CPU比作一个工厂,那么进程就好比工厂的车间,一个工厂有 ...
- ios基础篇(二十七)—— Json解析
一.什么是Json JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.它基于ECMAScript的一个子集. JSON采用完全独立于语言的文本格式,但是也使 ...
- ios基础篇(二十六)—— UITableViewCell的分组索引与标记
一.表视图的索引目录 首先要创建一个TableView,之前有说过,这里就不详细说了(参考前面第十四篇). 直接贴代码吧, #import "ViewController.h" @ ...
- ios基础篇(二十五)—— Animation动画(UIView、CoreAnimation)
Animation主要分为两类: 1.UIView属性动画 2.CoreAnimation动画 一.UIView属性动画 UIKit直接将动画集成到UIView类中,实现简单动画的创建过程.UIVie ...
- ios基础篇(二十四)—— 文字、图片的绘制及其自定义Button
这篇文章我们主要来拿官方的控件来研究一下,我们来仿照官方的控件,自己来实现它提供的控件: 首先来看看基本的图片与文字的绘制,很简单. 一.imageView 所有的视图都是继承自UIView,所以我们 ...
- ios基础篇(十四)——UITableView(二)属性及基本用法
上一篇说了UITableView的重用机制,让我们对UITableView有了简单了解,下面说说UITableView的属性及常见方法. 一.属性 1.frame:设置控件的尺寸和大小 2.backg ...
- ios基础篇(二十三)—— 定时器NSTimer与图片的自动切换
一.NSTimer NSTimer是一个能在从现在开始到后面的某一个时刻或者周期性的执行我们指定的方法的对象.可以按照一定的时间间隔,将制定的信息发送给目标对象.并更新某个对象的行为.你可以选择在未来 ...
随机推荐
- RDIFramework.NET ━ 9.5 组织机构管理 ━ Web部分
RDIFramework.NET ━ .NET快速信息化系统开发框架 9.5 组织机构管理 -Web部分 组织机构管理模块提供直观方便的组织机构管理,以树型结构显示单位和部门的机构体系,可根据需要进行 ...
- .Net分布式架构(一):Nginx实现负载均衡
一:负载均衡简介 负载均衡,英文名称为Load Balance,其意思就是分摊到多个操作单元上进行执行,例如Web服务器.FTP服务器.企业关键应用服务器和其它关键任务服务器等,从而共同完成工作任务. ...
- linux 查看磁盘剩余命令
df -hl命令查看各磁盘的大小,使用情况,挂载点等信息. du -bs dir_name查看具体目录的空间大小
- struts2数据校验与国际化
数据校验: Action里的validate()方法能校验action类所有的方法,如果有错,如:addFieldError,会自动返回到workflow校验拦截器不向下继续进行,不用return i ...
- Qt之自定义信号和槽函数
自定义信号和槽函数: 1.类的声明和实现分别放在.h和.cpp文件中: 2.类声明包含Q_OBJECT宏: 3.信号只要声明不要设计其的实现函数 4.发射信号用emit关键字 5.自定义槽的实现与普通 ...
- cxf(3.1.1) 异常Caused by: java.io.FileNotFoundException: class path resource [META-INF/cxf/cxf-extension-soap.xml]
Caused by: java.io.FileNotFoundException: class path resource [META-INF/cxf/cxf-extension-soap.xml] ...
- 手机APP测试体系
- string类find函数返回值判定
string类find函数返回值判定 代码示例 #include<iostream> #include<cstring> using namespace std; int m ...
- [转]为何需要调用“super viewDidLoad
转载地址:http://liwpk.blog.163.com/blog/static/36326170201165104413314/ - (void)didReceiveMemoryWarnin ...
- 利用javascript实现课程选择
最终实现的效果如下图所示: 代码如下所示: HTML代码部分: <body> <div class="page" style="overflow: hi ...