iPhone Radio Button Example

Ads
 

iPhone Radio Button Example

Can you please suggest me how to create Radio button in my iPhone application. Actually, in my application i have two images on UIButton 1) selected and 2) unselected ..what i want is, when a user click on that button it get selected and by default it should display unselected.

Thanks for any help in advance.

View Answers

March 6, 2011 at 2:23 PM

UIButton *Radiobutton = [UIButton buttonWithType:UIButtonTypeCustom];

 [Radiobutton setImage:[UIImage imageNamed:@"checkbox.png"] forState:UIControlStateNormal];

 [Radiobutton setImage:[UIImage imageNamed:@"checkedbox.png"] forState:UIControlStateSelected];

 [Radiobutton setFrame:CGRectMake(0, 0, 17, 17)];

 [Radiobutton addTarget:self action:@selector(checkboxButton:) forControlEvents:UIControlEventTouchUpInside];
     [self.view addSubview:Radiobutton];

and Action should be alike ----------------------------

- (IBAction)checkboxButton:(UIButton *)button{

     for (UIButton *Radiobutton in [self.view subviews]) {
          if ([Radiobutton isKindOfClass:[UIButton class]] && ![Radiobutton isEqual:button]) {
               [Radiobutton setSelected:NO];
          }
     }
     if (!button.selected) {
          button.selected = !button.selected;
     }
}

May 1, 2012 at 11:29 PM

Cool!Thanks for this code! But I want that to preserve the selected radiobutton,that when i again open that view ,the radiobutton which i had selected should remain selected.

Thanks in advance!

Ads









Related Tutorials/Questions & Answers:
iPhone Radio Button Example
iPhone Radio Button Example  Can you please suggest me how to create Radio button in my iPhone application. Actually, in my application i have two... click on that button it get selected and by default it should display unselected
info button iphone example
info button iphone example  I'm looking for a simple info button example in iPhone XCode. Thanks
Advertisements
radio button
radio button  On selecting a radio button, it should open a aspx page
validation of radio button
validation of radio button  There are 3 radio button as A,B,W. there are another radio as 1,2,3.if we select W in first radio button then should select 2nd one(1,2,3).if we select A or B not need select any one from 1,2,3
Struts 2 Radio Button
radio buttons and I am using Struts2 tag.I want first rado button to be selected by default.But when i select the second radio button and hit on search button i want to retain the selection of that second radio button on search list
How to play radio station on iPhone
How to play radio station on iPhone  how to play radio station on iphone
handling Button Event in iphone
handling Button Event in iphone  handling Button Event in iphone
java radio button and exception
java radio button and exception  Dear Sir/Madam, I have problem with my addBagelRadioButton and addCheeseRadioButton. There should be only 1 radio button can be selected, but somehow 2 can be selected the same time. Also, I
validate radio button using javascript
validate radio button using javascript  validate radio button using javascript
Radio button Validation
Radio button Validation  Hi.. How to validate radio button in java?if the radio button is not selected an error message should be given... Please...()==false)){ JOptionPane.showMessageDialog(null,"Please select radio button
Query on radio button
Query on radio button  I am having a multiple row in jsp page.They are dynamically coming. For each row there is one radio button. I want to select one row only, i.e I want to fetch the value of row and on submitting the page
dependent radio button
of the Radio Button is to select only one option at a time. So you don't need...dependent radio button  Hi. I have 4 radio buttons say all,chocolate,cookie,icecream. If I select all the other 3 should not able to be selected
passing value of radio button
passing value of radio button  hi,i have 3 jframe built using the GUi editor in net beans 6.9. i have two radio button in the first jframe.i have to get the selected item appear on the 3rd frame after passing through the second
access into radio button
access into radio button  access the four fields of database called access,access file and stored in radio button.please help
Radio Button Problem in jsp.
Radio Button Problem in jsp.  I have a small doubt in my application, my requirement is to get a "single selectible row", I generated a radio button... radio button values from jsp to action using javascript
iphone button click event
iphone button click event  Hi, How to write iphone button click event? Thanks   Hi, Here the method declaration: -(IBAction) myMetod...{ NSLog(@"Button clicked"); } Thanks
Radio buttons in html
Radio buttons in html Here is an example of radio button in html.In this example we have display two radio button Male and Female. The user select only one.... Example radioButton.html <html> <head><title>Radio button
Radio Button in HTML
Radio Button in HTML is a type of input form that allows a user to select one button from a group of button. When a user clicks on a radio button, it becomes...; specifies the component type is radio button or not. If a programmer use type="radio
On selecting a radio button, it should open a jsp page.
On selecting a radio button, it should open a jsp page.  Hi, COuld you please tell me how to link a radio button selection to a jsp. My requirement is if I select a radio button then it should open a jsp page. thank you
pass radio button values to next page
pass radio button values to next page  how to pass selected radio button values which coming from mysql database to next page using php. Please show me with examples
Struts2.2.1 radio Tag Example
Struts2.2.1 radio Tag Example The radio tag is a UI tag that render a radio button input field. The following Example will shows how to implement the radio...;title>Example radio Tag</title> </head> <
iPhone - MFMailcomposeviewcontroller example
iPhone - MFMailcomposeviewcontroller example  Hi! I'm looking for a mfmailcomposeviewcontroller example for both iPhone and iPad. Any suggestion?? Thanks
radio button value on edit action
radio button value on edit action  This is my edit.jsp code...In my......Problem 'm facing is on edit action 'm not retrieving radio button value..i have used if else logic..Bt its not working...My edit.jsp code is:-Radio button name
Retrieve value of radio button from database to form
Retrieve value of radio button from database to form  var gn=document.getElementsByName("empg"); //empg is name of radio input type. for(var i=0;i
check radio button on retrieving the value from database.
check radio button on retrieving the value from database.  HI i am... database and according to that i want to check the cash cheque radio button... information from database the i want to show cash radio button checked.How can i do
uialertview example iphone
uialertview example iphone  Hi, How to write uialertview example iphone code? Thanks   Hi, Please check UIAlertView Example. Thanks
Struts 2 radio button value problem
Struts 2 radio button value problem  When I use s:radio tag in struts 2, I'm not able to get the selected value using document.getElementById... gives first radio option's value as the value for any option selected. Ex
display contents on the same page by selecting a radio button
on the same page under the radio button...display contents on the same page by selecting a radio button  Bill...;input type="radio" name="bill_status " value="due" /> Received<
Get radio button value after submiting page
Get radio button value after submiting page  Radio buttons are dynamically generated.After selecting radio button & submitting the page , the value of the selected radio button get displayed in that jsp page. <
Drop down and radio button value on edit action
Drop down and radio button value on edit action  HI, I have... the value from dropdown and radio button.. But the problem goes with edit action... for text boxes..bt select default value for dropdown and radio button...How do
Radio button with values from a String ArrayList in JSP?
Radio button with values from a String ArrayList in JSP?  Radio button values in JSP ArrayList<String> cs = CourseAssignments.getInstance... input. I want to display a radio button near each course, then user selects one

Ads