UI2_视图切换
//
// ViewController.m
// UI2_视图切换
//
// Created by zhangxueming on 15/7/1.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "ViewController.h" @interface ViewController ()
{
NSInteger _tagIndex;//记录当前显示的视图
}
@end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UILabel *redLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 100, 320, 100)];
redLabel.backgroundColor = [UIColor redColor];
redLabel.tag = 1;
redLabel.text = @"红色";
redLabel.textAlignment = NSTextAlignmentCenter ;
[self.view addSubview:redLabel]; UILabel *blueLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 120, 320, 100)];
blueLabel.backgroundColor = [UIColor blueColor];
blueLabel.tag = 2;
blueLabel.text = @"蓝色";
blueLabel.textAlignment = NSTextAlignmentCenter ;
[self.view addSubview:blueLabel]; UILabel *greenLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 140, 320, 100)];
greenLabel.backgroundColor = [UIColor greenColor];
greenLabel.tag = 3;
greenLabel.text = @"绿色";
greenLabel.textAlignment = NSTextAlignmentCenter ;
[self.view addSubview:greenLabel]; UIButton *lastBtn = [UIButton buttonWithType:UIButtonTypeSystem];
lastBtn.frame = CGRectMake(40, 400, 100, 30);
[lastBtn setTitle:@"上一张" forState:UIControlStateNormal];
lastBtn.backgroundColor = [UIColor cyanColor];
[lastBtn addTarget:self action:@selector(lastBtnClicked) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:lastBtn]; UIButton *nextBtn = [UIButton buttonWithType:UIButtonTypeSystem];
nextBtn.frame = CGRectMake(self.view.frame.size.width-140, 400, 100, 30);
[nextBtn setTitle:@"下一张" forState:UIControlStateNormal];
nextBtn.backgroundColor = [UIColor cyanColor];
[nextBtn addTarget:self action:@selector(nextBtnClicked) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:nextBtn]; //设置当前显示的视图
_tagIndex = 3; self.view.backgroundColor = [UIColor blackColor];
} - (void)lastBtnClicked
{
_tagIndex--;
if (_tagIndex<1) {
_tagIndex = 3;
}
//根据传入的tag值取出对应的视图
UILabel *label = (UILabel *)[self.view viewWithTag:_tagIndex];
[self.view bringSubviewToFront:label];
} - (void)nextBtnClicked
{
_tagIndex++;
if (_tagIndex>3) {
_tagIndex = 1;
}
UILabel *label = (UILabel *)[self.view viewWithTag:_tagIndex];
[self.view bringSubviewToFront:label];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
UI2_视图切换的更多相关文章
- UI2_视图切换ViewController
// // SubViewController.h // UI2_视图切换 // // Created by zhangxueming on 15/7/3. // Copyright (c) 2015 ...
- iOS开发系列--视图切换
概述 在iOS开发中视图的切换是很频繁的,独立的视图应用在实际开发过程中并不常见,除非你的应用足够简单.在iOS开发中常用的视图切换有三种,今天我们将一一介绍: UITabBarController ...
- pushViewController addSubview presentModalViewController视图切换
1.pushViewController和popViewController来进行视图切换,首先要确保根视图是NavigationController,不然是不可以用的, pushViewContro ...
- IOS 视图切换动画
我在网上找到的这个小方法,被我举一反三使用的屡试不爽.比如用在,当视图需要执行某一方法跳转到新的一个UIView上,从底层渐变浮到最上层.就是一个不错的视觉效果或者当需要类似keyboard的效果从底 ...
- UI3_视图切换
// // ViewController.m // UI3_视图切换 // // Created by zhangxueming on 15/7/3. // Copyright (c) 2015年 z ...
- UI1_ViewController视图切换及Appdelegate
// // ThirdViewController.h // UI1_ViewController视图切换及Appdelegate // // Created by zhangxueming on 1 ...
- Tabbar视图切换,返回上一视图,添加item
前面有一篇博文iOS学习之Tab Bar的使用和视图切换 这是在AppDelegate里使用Tabbar,这样的程序打开就是TabbarView了,有时候我们需要给程序做一些帮助页面,或者登录页面,之 ...
- MFC视图切换大全总结
单纯视图之间的切换 单文档多视图切换是我在学习MFC中遇到的一个老大难问题,在今天总算是一一破解了.我觉得视图切换分为三个等级,第一是在未切分窗格的情况下切换视图类:第二是在分割窗格的一个窗格内实行视 ...
- Android的Activity切换动画特效库SwitchLayout,视图切换动画库,媲美IOS
由于看了IOS上面很多开发者开发的APP的视图界面切换动画体验非常好,这些都是IOS自带的,但是Android的Activity等视图切换动画并没有提供原生的,所以特此写了一个可以媲美IOS视图切换动 ...
随机推荐
- [Node.js] Configuring npm package.json scripts
With a node package manager's (npm) package.json script property, you can preconfigure common tasks ...
- IOS UIView子类UIScrollView
转自:http://www.cnblogs.com/nightwolf/p/3222597.html 虽然apple在IOS框架中提供了很多可以直接使用的UI控件,但是在实际开发当中我们通常都是要自己 ...
- LOVE代码收集
Love的截图函数 1 function love.load() love.filesystem.setIdentity("test") end function love.dra ...
- android stuido 在线安装svn插件,添加版本库无响应
问题:android stuido 中在线安装svn插件,添加版本库无响应. 原因: 由于android stuido 版本较高,在线安装1.6x 版本的svn,添加版本库一直没有响应,最后卡死.. ...
- 1.7.4.3 Parsers
Parsers 除了主查询解析器外,还有一些其他的查询解析器可以使用或者和主查询解析器连合使用.这部分描述了其他查询解析器的细节,并且给出了一些例子: 大多数的解析器都可以使用局部查询参数的方式来表达 ...
- iOS 手机 邮箱 正则表达式
//iOS代码//判断邮箱格式是否正确的代码: //利用正则表达式验证 -(BOOL)isValidateEmail:(NSString *)email { NSString *emailRegex ...
- C#三大支柱之继承
1.使用base 若子类需要使用父类公开或受保护的成员则需要是base class Manager : Employee { public int StockOptions { get; set; } ...
- VMware系统运维(八)vCenter Server安装
1.终于开始安装vCenter Server了,需要配置数据源哦! 2.下一步 3.接受协议,下一步 4.输入许可密钥,也可以后面再输入,下一步 5.选择数据源,即我们前面配置的系统DSN,下一步 6 ...
- [转]如何烧录tizen镜像文件?(图文教程)
http://blog.csdn.net/flydream0/article/details/9179143 上一篇文章我已讲过如何制作镜像文件(http://blog.csdn.net/flydre ...
- http header详解
HTTP(HyperTextTransferProtocol)即超文本传输协议,目前网页传输的的通用协议.HTTP协议采用了请求/响应模 型,浏览器或其他客户端发出请求,服务器给与响应.就整个网络资源 ...