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视图切换动 ...
随机推荐
- Delphi开发OCX详细步骤总结
首先要弄明白你要写的OCX是用在客户端还是用在服务器端 假如用在客户端: 1.创建 打开delphi 7,选择菜单"new"->"other"- ...
- opencv china 网站,好1376472449
http://www.opencvchina.com/thread-1750-1-2.html
- Linux的内存回收和交换
Linux的内存回收和交换 版权声明: 本文章内容在非商业使用前提下可无需授权任意转载.发布. 转载.发布请务必注明作者和其微博.微信公众号地址,以便读者询问问题和甄误反馈,共同进步. 微博ID:or ...
- 除去字符串中不相临的重复的字符 aabcad 得 aabcd
假设有一个字符串aabcad,请编写一段程序,去掉字符串中不相邻的重复字符.即上述字串处理之后结果是为:aabcd; 分析,重点考查 char 与int 的隐式转换.程序如下: static void ...
- 深入理解Redis中的主键失效及其实现机制
参考:http://blog.sina.com.cn/s/articlelist_1221155353_0_1.html 作为一种定期清理无效数据的重要机制,主键失效存在于大多数缓存系统中,Reids ...
- NoSQL数据库的分布式算法&&memcache集群的实现
NoSQL数据库的分布式算法 http://blog.nosqlfan.com/html/4139.html 一致性hash算法在memcache集群中的应用 http://alunblog.d ...
- Python Learning
这是自己之前整理的学习Python的资料,分享出来,希望能给别人一点帮助. Learning Plan Python是什么?- 对Python有基本的认识 版本区别 下载 安装 IDE 文件构造 Py ...
- LeetCode40 Combination Sum II
题目: Given a collection of candidate numbers (C) and a target number (T), find all unique combination ...
- Docker 选项和命令
选项 -D=true|false 使用 debug 模式.默认为 false. -H, --host=[unix:///var/run/docker.sock]: tcp://[host:port]来 ...
- 【python调用windows CLI】调用adb统计Android app的流量消耗
主要记录python如何调用windows CLI 手机连接PC,adb devices可以看到手机sn 通过adb 获取指定app的processID UID 读取Android /proc/ne ...