Member-only story
iOS Tutorials: Making radio buttons
Originally published on: https://daddycoding.com/2019/08/07/ios-tutorials-making-radio-buttons/
OVERVIEW
Radio button become one of the choices if the app requires additional informations from the user as it retrieves choice picked by user. It is also one of a way to know the user preference. Isn’t it considered user friendly if the user is able to pick their own choice?
Let’s dive into making a radio button work for the apps.
BUILDING THE UITABLEVIEWCELL
First, create a custom UITableViewCell by New > File > Cocoa Touch Class
Make sure that the subclass is of type UITableViewCell and Also create XIB file is checked.
It should look pretty straight forward with an image and a button on the UITableViewCell.
When all the above is done. It’s time to write a little code that will handle the text and the selection. This is how the code will look like.
import UIKitclass RadioButtonTableViewCell: UITableViewCell { // 1
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var iconImage: UIImageView! // 2
private let checked = UIImage(named: "checked-radio")
private let unchecked = UIImage(named: "unchecked-radio") // 3
override func awakeFromNib() {
super.awakeFromNib()
}