zoukankan      html  css  js  c++  java
  • iphone 使用按钮实现单选框

    //画图 

    -(void)addSecondZone:(UIView*)contentView

    //按钮图片

    UIImage *selecticonNo =[UIImage imageNamed:SelecticonNo];

    UIImage *selecticon =[UIImage imageNamed:Selecticon]; 

            UIView *childSecondView; 

            childSecondView = [[UIView alloc] initWithFrame:CGRectMake(0, 155 , 320, 500)];


           int pointY =0;

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

    [childSecondView addSubImageView:contentbar Rect:CGRectMake(0, pointY, 320,contentbar.size.height/2)];

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

    [button setBackgroundImage:selecticonNo forState:UIControlStateNormal];

    [button setBackgroundImage:selecticon forState:UIControlStateSelected];

    button.frame=CGRectMake(310-selecticonNo.size.width/2, pointY+2,                               selecticonNo.size.width/2,selecticonNo.size.height/2);

    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

    button.tag=i + 1;

    [button addTarget:self action:@selector(selectTransType:) forControlEvents:UIControlEventTouchUpInside];

    if(i==0)

    {

    [button setSelected:YES];

    }

    [childSecondView addSubview:button];

    pointY += 40;

    } 

     }

    //单选框点击

    -(void)selectTransType:(id)sender

    {


    //单选钮

    UIImage *selecticonNo =[UIImage imageNamed:SelecticonNo];

    UIImage *selecticon =[UIImage imageNamed:Selecticon];

    UIButton *btn=nil;


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

    btn = (UIButton *)[mainZone viewWithTag:i];   //获取单选按钮  mainZone 是最外层的视图

    if ([btn isSelected]) {

    [btn setBackgroundImage:selecticonNo forState:UIControlStateNormal];

    [btn setSelected:NO];

    }

    }

    [sender setBackgroundImage:selecticon forState:UIControlStateSelected]; 

    [sender setSelected:YES];

    } 

  • 相关阅读:
    Java核心(七):this和super的区别
    Java核心(六):==和equals()的区别;重写equals()方法
    java核心(五):堆内存、栈内存;String赋值时,内存变化
    Java核心(四):Java中的装箱和拆箱
    Java核心(三):代码块的作用
    从数据库中导出.csv文件
    mongodb中数据类型的坑
    return 和 echo 的小坑
    对数据库中初始的数据在后台进行翻译
    SQL语句执行效率及分析
  • 原文地址:https://www.cnblogs.com/lvlin/p/2035592.html
Copyright © 2011-2022 走看看