首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Iphone >

iphone开发兑现单选框

2013-04-09 
iphone开发实现单选框//画图 -(void)addSecondZone:(UIView*)contentView//按钮图片UIImage *selecticonNo

iphone开发实现单选框

//画图 

-(void)addSecondZone:(UIView*)contentView

//按钮图片

UIImage *selecticonNo =[UIImageimageNamed: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++) {

[childSecondViewaddSubImageView: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 =[UIImageimageNamed:SelecticonNo];

UIImage *selecticon =[UIImageimageNamed:Selecticon];

UIButton *btn=nil;


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

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

if ([btnisSelected]) {

[btnsetBackgroundImage:selecticonNo forState:UIControlStateNormal];

[btn setSelected:NO];

}

}

[sendersetBackgroundImage:selecticon forState:UIControlStateSelected]; 

[sendersetSelected:YES];

热点排行