//
// 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_视图切换的更多相关文章

  1. UI2_视图切换ViewController

    // // SubViewController.h // UI2_视图切换 // // Created by zhangxueming on 15/7/3. // Copyright (c) 2015 ...

  2. iOS开发系列--视图切换

    概述 在iOS开发中视图的切换是很频繁的,独立的视图应用在实际开发过程中并不常见,除非你的应用足够简单.在iOS开发中常用的视图切换有三种,今天我们将一一介绍: UITabBarController ...

  3. pushViewController addSubview presentModalViewController视图切换

    1.pushViewController和popViewController来进行视图切换,首先要确保根视图是NavigationController,不然是不可以用的, pushViewContro ...

  4. IOS 视图切换动画

    我在网上找到的这个小方法,被我举一反三使用的屡试不爽.比如用在,当视图需要执行某一方法跳转到新的一个UIView上,从底层渐变浮到最上层.就是一个不错的视觉效果或者当需要类似keyboard的效果从底 ...

  5. UI3_视图切换

    // // ViewController.m // UI3_视图切换 // // Created by zhangxueming on 15/7/3. // Copyright (c) 2015年 z ...

  6. UI1_ViewController视图切换及Appdelegate

    // // ThirdViewController.h // UI1_ViewController视图切换及Appdelegate // // Created by zhangxueming on 1 ...

  7. Tabbar视图切换,返回上一视图,添加item

    前面有一篇博文iOS学习之Tab Bar的使用和视图切换 这是在AppDelegate里使用Tabbar,这样的程序打开就是TabbarView了,有时候我们需要给程序做一些帮助页面,或者登录页面,之 ...

  8. MFC视图切换大全总结

    单纯视图之间的切换 单文档多视图切换是我在学习MFC中遇到的一个老大难问题,在今天总算是一一破解了.我觉得视图切换分为三个等级,第一是在未切分窗格的情况下切换视图类:第二是在分割窗格的一个窗格内实行视 ...

  9. Android的Activity切换动画特效库SwitchLayout,视图切换动画库,媲美IOS

    由于看了IOS上面很多开发者开发的APP的视图界面切换动画体验非常好,这些都是IOS自带的,但是Android的Activity等视图切换动画并没有提供原生的,所以特此写了一个可以媲美IOS视图切换动 ...

随机推荐

  1. 2013 French Open Semifinal Press

    http://v.youku.com/v_show/id_XNTY4MTgzOTEy.html?firsttime=0 Novak, can you take any confirt   for qu ...

  2. SexyProgressBar

    https://github.com/sunalong/SexyProgressBar

  3. Timing advance of GSM(时间提前量)

    基本概念 时间提前量TA(Timing Advance)的作用是为了补偿电波传输延迟,而根本目的则是为了提高信道编解码效率.由于GSM采用TDMA,每载频8个时隙,应严格保持时隙间的同步,没有TA就无 ...

  4. [原创]-CMD命令设置IP地址

    问题描述 在实际工作中,尤其是像我们这种BI分析人员,在做项目的时候,时常都需要因客户的不同随时切换不同的网络环境,有时可能需要在公司和客户之间来回的穿梭.交替.问题也就随之而来:每次客户那里都需要设 ...

  5. 疑难杂症:org.hibernate.MappingException: Unknown entity,annotation配置Entity类报错

    引言: 夜声人静,外面下着稀里哗啦的雨,周末的晚上,还在键盘上舞动手指. 此刻很感激一个人一篇随笔,感谢xiaochao以及他的<org.hibernate.MappingException: ...

  6. 代码片段 - Golang 创建 .tar.gz 压缩包

    Golang创建 .tar.gz 压缩包 tar 包实现了文件的打包功能,可以将多个文件或目录存储到单一的 .tar 文件中,tar 本身不具有压缩功能,只能打包文件或目录: import " ...

  7. Golang学习 - unicode/utf8 包

    ------------------------------------------------------------ // 编码所需的基本数字 const ( RuneError = '\uFFF ...

  8. windows和linux中检查端口是否被占用

    一.windows 1.查询端口占用情况 cmd > netstat -ano 2.查询8080端口是否被占用 cmd > netstat -ano|findstr 8080 3.查询哪个 ...

  9. org.apache.hadoop.conf-Configurable

    从包名可以看出这个包里面都是配置相关的类:从类名上可以看出这是一个接口,或者说配置类接口.内容很少. package org.apache.hadoop.conf; /** Something tha ...

  10. 开发工具 之 PowerDesigner

    PowerDesigner是一款功能非常强大的建模工具软件,足以与Rose比肩,同样是当今最著名的建模软件之一.Rose是专攻UML对象模型的建模工具,之后才向数据库建模发展,而PowerDesign ...