学习笔记--两个UIView之间跳转、tag,UIAlertView基本使用

一、两个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];

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值