多个点击按钮事件 老大教的

-(void)createButton

{

    

    NSArray *datarr=[NSArray arrayWithObjects:@"周一",@"周二",@"周三",@"周四",@"周五", nil];

    NSArray *shuziarr=[NSArray arrayWithObjects:@"49",@"50",@"16",@"27",@"35", nil];

    

    for (int i=0; i<5; i++) {

        UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];

        btn.frame=CGRectMake(7+i*62, 3, 60, 60);

//        btn.tintColor=[UIColor blueColor];

        

        btn.tag=i+100;//每个东西 只会有一个tag

        [btn setImage:[UIImage imageNamed:@"u34_normal"] forState:UIControlStateNormal];

        [btn addTarget:self action:@selector(pressShou:) forControlEvents:UIControlEventTouchUpInside];

        [self.view addSubview:btn];

        

      UILabel *data=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 60, 30)];

        data.tag=i+200;//tag 都不可以设置重复的

     data.textAlignment=NSTextAlignmentCenter;

     data.text=[datarr objectAtIndex:i];

     data.font=[UIFont systemFontOfSize:15.0f];

     data.backgroundColor=[UIColor clearColor];

     [btn addSubview:data];

     [data release];

     

      UILabel *shuzi=[[UILabel alloc] initWithFrame:CGRectMake(0, 30, 60, 30)];

     shuzi.textAlignment=NSTextAlignmentCenter;

     shuzi.text=[shuziarr objectAtIndex:i];

        shuzi.tag=i+300;

     shuzi.font=[UIFont systemFontOfSize:15.0f];

     shuzi.backgroundColor=[UIColor clearColor];

     [btn addSubview:shuzi];

     [shuzi release];

        

                

     

    }

    

   

   /*

    for (int i=0; i<5; i++) {

        UIImageView *image=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"u34_normal"]];

        image.userInteractionEnabled=YES;

        image.frame=CGRectMake(7+i*62, 3, 60, 60);

        [self.view addSubview:image];

        [image release];

        UILabel *data=[[UILabel alloc] initWithFrame:CGRectMake(10, 3, 40, 30)];

        data.textAlignment=NSTextAlignmentCenter;

        data.text=[datarr objectAtIndex:i];

        data.font=[UIFont systemFontOfSize:15.0f];

        [image addSubview:data];

        [data release];

        

        UILabel *shuzi=[[UILabel alloc] initWithFrame:CGRectMake(10, 30, 40, 20)];

        shuzi.textAlignment=NSTextAlignmentCenter;

        shuzi.text=[shuziarr objectAtIndex:i];

        shuzi.font=[UIFont systemFontOfSize:15.0f];

        [image addSubview:shuzi];

        [shuzi release];

        

        

        

    }*/

}


-(void)pressShou:(UIButton*)btn

{

    for (int i = 0; i < 5; i++) {

        UILabel *data=(UILabel *)[self.view viewWithTag:200+i];

        UILabel *shuzi=(UILabel *)[self.view viewWithTag:300+i];

        if (btn.tag != i+100) {

            data.backgroundColor=[UIColor clearColor];

            

            shuzi.backgroundColor=[UIColor clearColor];

            shuzi.textColor=Black1;

            data.textColor=Black1;


    }

        else {

            

            

            shuzi.backgroundColor=[UIColor blueColor];

            data.backgroundColor=[UIColor blueColor];

            shuzi.textColor=white1;

            data.textColor=white1;

            data.font=[UIFont boldSystemFontOfSize:15.0f];

            shuzi.font=[UIFont boldSystemFontOfSize:15.0f];


        }

    }

    

    return;

    

//    if (btn.tag==100) {

//        UILabel *data=(UILabel *)[self.view viewWithTag:200];

//        UILabel *shuzi=(UILabel *)[self.view viewWithTag:300];

//        data.backgroundColor=[UIColor blueColor];

//        

//        shuzi.backgroundColor=[UIColor blueColor];

//        shuzi.textColor=white1;

//         data.textColor=white1;

//

//

//    }

//    else if(btn.tag==101){

//        UILabel *data=(UILabel *)[self.view viewWithTag:201];

//        UILabel *shuzi=(UILabel *)[self.view viewWithTag:301];

//        data.backgroundColor=[UIColor blueColor];

//        shuzi.backgroundColor=[UIColor blueColor];

//        shuzi.textColor=white1;

//        data.textColor=white1;

//

//

//    }

//    else if(btn.tag==102){

//        UILabel *data=(UILabel *)[self.view viewWithTag:202];

//        UILabel *shuzi=(UILabel *)[self.view viewWithTag:302];

//        data.backgroundColor=[UIColor blueColor];

//        shuzi.backgroundColor=[UIColor blueColor];

//        shuzi.textColor=white1;

//        data.textColor=white1;

//

//

//    }

//    else if(btn.tag==103){

//        UILabel *data=(UILabel *)[self.view viewWithTag:203];

//        UILabel *shuzi=(UILabel *)[self.view viewWithTag:303];

//        data.backgroundColor=[UIColor blueColor];

//        shuzi.backgroundColor=[UIColor blueColor];

//        shuzi.textColor=white1;

//        data.textColor=white1;

//

//

//    }

//    else{

//        UILabel *data=(UILabel *)[self.view viewWithTag:204];

//        UILabel *shuzi=(UILabel *)[self.view viewWithTag:304];

//        data.backgroundColor=[UIColor blueColor];

//        shuzi.backgroundColor=[UIColor blueColor];

//        shuzi.textColor=white1;

//        data.textColor=white1;

//

//

//

//    }

    


}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值