Best radio-button implementation for IOS
Solution 1
I have some thoughts on how the best radio button implementation should look like. It can be based on UIButton
class and use it's 'selected' state to indicate one from the group. The UIButton
has native customisation options in IB, so it is convenient to design XIBs.
Also there should be an easy way to group buttons using IB outlet connections:
I have implemented my ideas in this RadioButton class. Works like a charm:
Solution 2
Try UISegmentedControl. It behaves similarly to radio buttons -- presents an array of choices and lets the user pick 1.
Solution 3
Just want to sum up, there might be 4 ways.
- If you don't have much space, add a click event for text or button, then show UIPickerView:
or open a new table view control with a check mark:
- If there is more space, add a table view directly to your main view:
- The final solution is using UISegmentedControl:
Hope this helps.
Solution 4
Try DLRadioButton, works for both Swift
and ObjC
. You can also use images to indicate selection status or customize your own style.
Check it out at GitHub.
**Update: added the option for putting selection indicator on the right side.
**Update: added square button, IBDesignable
, improved performance.
**Update: added multiple selection support.
Solution 5
I know its very late to answer this but hope this may help anyone.
you can create button like radio button using IBOutletCollection
. create one IBOutletCollection property in our .h file.
@property (nonatomic, strong) IBOutletCollection(UIButton) NSArray *ButtonArray;
connect all button with this IBOutletCollection and make one IBAction method for all three button.
- (IBAction)btnTapped:(id)sender {
for ( int i=0; i < [self.ButtonArray count]; i++) {
[[self.ButtonArray objectAtIndex:i] setImage:[UIImage
imageNamed:@"radio-off.png"]
forState:UIControlStateNormal];
}
[sender setImage:[UIImage imageNamed:@"radio-on.png"]
forState:UIControlStateNormal];
}
Jonas Arcangel
Updated on July 12, 2020Comments
-
Jonas Arcangel almost 4 years
I would like to ask if there are examples out there on how to implement radio-button options on an iPhone app.
I find the Picker View quite big for a simple selection feature.
I'm not sure if Apple excluded radio buttons on purpose, and whether if it is better to simply use a Picker View from a usability / user experience point-of-view.