学习笔记--两个UIView之间跳转、tag,UIAlertView基本使用
2015-05-18 20:25
555 查看
一、两个UIView之间的跳转
//在.h文件中定义全局view_1、view_2
-(void)toView1{
if(!view_2){
[view_2 removeFromSuperview];
}
view_1 = [[UIView alloc]initWithFrame:CGRectMake(0,0,320,480)];
[self.window addSubview:view_1];
UIImageView *imageView_1 = [[UIImageView alloc]initWithFrame:CGRectMake(0,0,320,480)];
imageView_1.image = [UIImage imageNamed:@"pic1"];
[view_1 addSubview:imageView_1];
UIButton *button_1 = [UIButton buttonWithType:UIButtonTypeSystem];
button_1.frame = CGRectMake(0,0,320,480);
[button_1 addTarget:self action:@selector(toView2) forControlEvents:UIControlEventTouchUpInside];
[view_1 addSubview:button_1];
}
-(void)toView2{
[view_1 removeFromSuperview];
view_2 = [[UIView alloc]initWithFrame:CGRectMake(0,0,320,480)];
[self.window addSubview:view_2];
UIImageView *imageView_2 = [[UIImageView alloc]initWithFrame:CGRectMake(0,0,320,480)];
imageView_2.image = [UIImage imageNamed:@"pic2"];
[view_2 addSubview:imageView_2];
UIButton *button_2 = [UIButton buttonWithType:UIButtonTypeSystem];
button_2.frame = CGRectMake(0,0,320,480);
[button_2 addTarget:self action:@selector(toView1) forControlEvents:UIControlEventTouchUpInside];
[view_2 addSubview:button_2];
}
二、tag作用:可以为控件定义一个值,来区分控件。
通过改变背景颜色测试tag的调用
-(void)clickButton{
UIButton *button_1 = [UIButton buttonWithType:UIButtonTypeSystem];
button_1.frame = CGRectMake(100,100,120,40);
[button_1 addTarget:self action:@selector(testTag:) forControlEvents:UIControlEventTouchUpInside];
button_1.tag = 10000;
[self.window addSubview:button_1];
UIButton *button_2 = [UIButton buttonWithType:UIButtonTypeSystem];
button_2.frame = CGRectMake(100,160,100,40);
[button_2 addTarget:self action:@selector(testTag:) forControlEvents:UIControlEventTouchUpInside];
button_2.tag = 20000;
[self.window addSubview:button_2];
}
-(void)testTag:(id)sender{
switch([sender tag]){
case 10000:
[self.window.backgroundColor [UIColor purpleColor]];
break;
case 20000:
[self.window.backgroundColor [UIColor grayColor]];
break;
default:
break;
}
}
三、UIAlertView提示框(仅显示,功能未实现)
定义提示框:
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"有提示:" message:@"输入错误,请重试" delegate:self cancelButton:@"取消" otherButton:@"第一button",@"第二button",nil];//可定义多个
[alert show];
//在.h文件中定义全局view_1、view_2
-(void)toView1{
if(!view_2){
[view_2 removeFromSuperview];
}
view_1 = [[UIView alloc]initWithFrame:CGRectMake(0,0,320,480)];
[self.window addSubview:view_1];
UIImageView *imageView_1 = [[UIImageView alloc]initWithFrame:CGRectMake(0,0,320,480)];
imageView_1.image = [UIImage imageNamed:@"pic1"];
[view_1 addSubview:imageView_1];
UIButton *button_1 = [UIButton buttonWithType:UIButtonTypeSystem];
button_1.frame = CGRectMake(0,0,320,480);
[button_1 addTarget:self action:@selector(toView2) forControlEvents:UIControlEventTouchUpInside];
[view_1 addSubview:button_1];
}
-(void)toView2{
[view_1 removeFromSuperview];
view_2 = [[UIView alloc]initWithFrame:CGRectMake(0,0,320,480)];
[self.window addSubview:view_2];
UIImageView *imageView_2 = [[UIImageView alloc]initWithFrame:CGRectMake(0,0,320,480)];
imageView_2.image = [UIImage imageNamed:@"pic2"];
[view_2 addSubview:imageView_2];
UIButton *button_2 = [UIButton buttonWithType:UIButtonTypeSystem];
button_2.frame = CGRectMake(0,0,320,480);
[button_2 addTarget:self action:@selector(toView1) forControlEvents:UIControlEventTouchUpInside];
[view_2 addSubview:button_2];
}
二、tag作用:可以为控件定义一个值,来区分控件。
通过改变背景颜色测试tag的调用
-(void)clickButton{
UIButton *button_1 = [UIButton buttonWithType:UIButtonTypeSystem];
button_1.frame = CGRectMake(100,100,120,40);
[button_1 addTarget:self action:@selector(testTag:) forControlEvents:UIControlEventTouchUpInside];
button_1.tag = 10000;
[self.window addSubview:button_1];
UIButton *button_2 = [UIButton buttonWithType:UIButtonTypeSystem];
button_2.frame = CGRectMake(100,160,100,40);
[button_2 addTarget:self action:@selector(testTag:) forControlEvents:UIControlEventTouchUpInside];
button_2.tag = 20000;
[self.window addSubview:button_2];
}
-(void)testTag:(id)sender{
switch([sender tag]){
case 10000:
[self.window.backgroundColor [UIColor purpleColor]];
break;
case 20000:
[self.window.backgroundColor [UIColor grayColor]];
break;
default:
break;
}
}
三、UIAlertView提示框(仅显示,功能未实现)
定义提示框:
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"有提示:" message:@"输入错误,请重试" delegate:self cancelButton:@"取消" otherButton:@"第一button",@"第二button",nil];//可定义多个
[alert show];
相关文章推荐
- 使用Intent对象来实现两个(或多个)Activity之间的跳转,并实现在Activity之间传递参数。
- UIAlertView 的基本使用方法
- IOS delegate 委托 使用 两个View之间传数据
- 两个ViewController之间跳转的动画效果
- iOS 使用tableview,实现两个页面跳转及使用协议时错误记录
- 【总结】在两个Activity之间进行跳转时出错原因分析(一)——findViewById位置不当导致
- IOS学习笔记(九)之UIAlertView(警告视图)和UIActionSheet(操作表视图)基本概念和使用方法
- IOS学习笔记(九)之UIAlertView(警告视图)和UIActionSheet(操作表视图)基本概念和使用方法
- 使用Delegate在两个ViewController之间传值
- UIAlertView的基本使用和对话框中按钮的事件处理方法
- Button点击后,如何实现两个view之间的跳转
- UIAlertViewController 基本使用+自定义(字体颜色,大小,对齐方式)
- ViewPager + Fragment处理两个Fragment的点击跳转以及之间的传递数据
- UIAlertView的基本使用
- iOS UIAlertView的基本使用
- ViewPager + Fragment处理两个Fragment的点击跳转以及之间的传递数据
- Recycleview的基本使用方法
- 两个App之间进行跳转与传值
- ios ViewController的生命周期分析和基本使用逻辑
- RecyclerView的基本使用