你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iphone開發實現單選框

iphone開發實現單選框

編輯:IOS開發綜合

//畫圖

-(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];


}

 

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved