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视图切换动 ...
随机推荐
- osg轮廓特效 【转】
// -*-c++-*- /* * OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield * * This library is open s ...
- Android 百度地图定位(手动+自动) 安卓开发教程
近由于项目需要,研究了下百度地图定位,他们提供的实例基本都是用监听器实现自动定位的.我想实现一种效果:当用户进入UI时,不定位,用户需要定位的时候,自己手动点击按钮,再去定位当前位置. 经过2天研究 ...
- curl命令具体解释
对于windows用户假设用Cygwin模拟unix环境的话,里面没有带curl命令,要自己装,所以建议用Gow来模拟,它已经自带了curl工具,安装后直接在cmd环境中用curl命令就可,由于路径已 ...
- android Activity的杂乱总结
android中Activity可以说是四大组件中用的最为广泛,也是最为基本的一个组件.几乎和用户的所有交互都需要通过Activity来实现. 最近在学习过程中,有一些关于Activity的内容,让我 ...
- iOS开发——语法OC篇&BOOL / bool / Boolean / NSCFBoolean
Name Typedef Header True Value False Value BOOL signed char objc.h YES NO bool _Bool (int) stdbool.h ...
- h5-3
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- SQL Server 查看死锁的存储过程(转载)
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_who_lock]') and ) drop proc ...
- gridview_RowCommand 获取当前行中的控件
<asp:GridView ID="gvStorglog" runat="server" Width="100%" SkinID=&q ...
- The calculation of GPA
Problem Description 每学期的期末,大家都会忙于计算自己的平均成绩,这个成绩对于评奖学金是直接有关的.国外大学都是计算GPA(grade point average) 又称GPR(g ...
- ASP.NET 批量更新
ASP.NET三种常用批量操作: 一.SqlBulkCopy copy = new SqlBulkCopy("");(优先考虑 性能最优) SqlBulkCopy可以将一个Data ...