A sample project demonstrates the usage of SHSelection Class to implement checkbox and radio buttons easily.
Just drag and drop the SHSelections folder to your project.
- Just drag and drop an Table View in storyboard and set Table View class to SHSelections and set an outlet.
- How to configure:
@IBOutlet weak var checkboxSelection: SHSelections!
override func viewDidLoad() {
super.viewDidLoad()
checkboxSelection.selectionType = .checkbox // by default .checkbox
checkboxSelection.items = ["CheckBox item 1","CheckBox item 2","CheckBox item 3","CheckBox item 4"]
checkboxSelection.checkedIcon = UIImage(named: "some image name")!
checkboxSelection.unCheckedIcon = UIImage(named: "some image name")!
}
- for checkbox :
selectionType = .checkbox
- for radio button :
selectionType = .radio
- for items to display :
items = ["CheckBox item 1"] \\pass an array of string
- for icons(for custom icons) :
\\by default it has icons, you can pass custom icons
\\Check box
checkedIcon = UIImage(named: "some image name")!
unCheckedIcon = UIImage(named: "some image name")!
\\Radio button
radioEmptyIcon = UIImage(named: "some image name")!
radioSelectedIcon = UIImage(named: "some image name")!
- Setting delegate :
class ViewController: UIViewController,SHSelectionProtocol {
@IBOutlet weak var checkboxSelection: SHSelections!
override func viewDidLoad() {
super.viewDidLoad()
checkboxSelection.selectionDelegate = self
-
-
-
}
//Delegate methods
//Radio Button selected Index
func getRadioIndex(index: Int) {
print(index)
}
//Radio Button selected item
func getRadioItem(item: String) {
print(item)
}
68D7
//Checkbox all selected Indexes
func getCheckboxIndex(indexes: [Int]) {
print(indexes)
}
//Checkbox all selected Indexes
func getCheckboxItems(items: [String]) {
print(items)
}
}
- to get checkbox selected index array :
func getCheckboxIndex(indexes: [Int]){ }
- to get checkbox selected items array :
func getCheckboxItems(items: [String]){ }
- to get radio button selected index :
func getRadioIndex(index: Int){ }
- to get radio button selected item :
func getRadioItem(item: String)
- iOS 10.0+
Download the Sample project.
Mail me @: shezadahamed95@gmail.com