zoukankan      html  css  js  c++  java
  • iphone开发实现单选框

    //画图 

    -(void)addSecondZone:(UIView*)contentView

    //按钮图片

    UIImage *selecticonNo =[UIImage imageNamed:SelecticonNo];

    UIImage *selecticon =[UIImageimageNamed:Selecticon]; 

            UIView *childSecondView; 

            childSecondView = [[UIViewalloc] 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 = [UIButtonbuttonWithType:UIButtonTypeCustom];

    [buttonsetBackgroundImage:selecticonNo forState:UIControlStateNormal];

    [buttonsetBackgroundImage:selecticon forState:UIControlStateSelected];

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

    [buttonsetTitleColor:[UIColorblackColor] forState:UIControlStateNormal];

    button.tag=i + 1;

    [buttonaddTarget:selfaction:@selector(selectTransType:) forControlEvents:UIControlEventTouchUpInside];

    if(i==0)

    {

    [buttonsetSelected:YES];

    }

    [childSecondViewaddSubview: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];

     

    } 

  • 相关阅读:
    每个android项目都应该使用的android 库
    解决android锁屏或解锁后activity重启的问题
    Git提交时提示‘The file will have its original line endings in your working directory’
    homestead虚拟机,通过npm下载依赖包和解决运行gulp报错问题 yarn出错问题
    免费获取验证码60秒倒计时
    html5表单验证(Bootstrap)
    jQuery 创建html
    HTML5中音频视频标签使用
    分享到朋友圈遮罩层
    TP细节总结1
  • 原文地址:https://www.cnblogs.com/xinyuyuanm/p/3003888.html
Copyright © 2011-2022 走看看