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视图切换动 ...
随机推荐
- 谷歌技术"三宝"之MapReduce
江湖传说永流传:谷歌技术有"三宝",GFS.MapReduce和大表(BigTable)! 谷歌在03到06年间连续发表了三篇非常有影响力的文章,各自是03年SOSP的GFS,04 ...
- NGUI ERROR:UnityException: Sprite is not rectangle-packed. TextureRect is invalid.解决
在使用Ngui 3.4.9的时候,使用“Unity 2D Sprite”控件的时候,出现了UnityException: Sprite is not rectangle-packed. Texture ...
- [ES6] 14. Generator -- 1. yield & next()
Generators in ECMAscript 6 are first-class coroutines that produce encapsulated suspended execution ...
- iOS开发——UI高级OC篇&自定义控件之调整按钮中子控件(图片和文字)的位置
自定义控件之调整按钮中子控件(图片和文字)的位置 其实还有一种是在storyBoard中实现的,只需要设置对应空间的左右间距: 这里实现前面两种自定义的方式 一:imageRectForContent ...
- iOS开发——测试篇&breakpoints、lldb 和 chisel 的详解
breakpoints.lldb 和 chisel 的详解 Breakpoints BreakPoint分类 breakpoint也是有分类的,我这里的文章内大致按使用的方式分为了 Normal Br ...
- mysqldump中master-data和dump-slave的区别
[mysql@db2 ~]$ mysqldump -A --master-data=2 > master2.sql [mysql@db2 ~]$ mysqldump -A --dump-sl ...
- UML 之 各种视图简介
统一建模语言(Unified Modeling Language,UML)中各种视图并没有明显的概念区别. 在最上一层,视图被划分为三个视图域:结构,动态行为,模型管理. 结构主要描述了系统中的结构成 ...
- 【阿里云产品公测】云引擎ACE初体验
作者:阿里云用户蓝色之鹰 :RYYjmG5; 来投票支持我把=i2]qj\ 序号2. [阿里云产品公测]云引擎ACE初体验:作者:蓝色之鹰 e(OKE7 序号10.[阿里云产品公测]结构化数据服 ...
- 重构23-Introduce Parameter Object(参数对象)
有 时当 使用 一个 包含 多 个 参 数 的 方 法 时 , 由 于参 数 过 多 会 导 致 可 读 性 严 重 下 降 , 如 : 有 时当 使用 一个 包含 多 个 参 数 的 方 法 时 , ...
- System.Data.OracleClient requires Oracle client software version 8.1.7 or greater
It is a security issue, so to fix it simply do the following: Go to the Oracle folder. 1- Right Clic ...