SwiftCheckboxDialog
概览
SwiftCheckboxDialog 是一个简单的对话框,包含多个多选复选框,使用 Swift 4.2 和 xCode 10 编写
需求
- ARC
- iOS12
使用 CocoaPods 安装
SwiftCheckboxDialog 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod "SwiftCheckboxDialog"
使用
import SwiftCheckboxDialog
class ViewController: UIViewController, CheckboxDialogViewDelegate {
var checkboxDialogViewController: CheckboxDialogViewController!
//define typealias-es
typealias TranslationTuple = (name: String, translated: String)
typealias TranslationDictionary = [String : String]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func onButtonPressed(_ sender: UIButton) {
// this tuple has translated key because it can use localized values in case app needs to be localized
let tableData :[(name: String, translated: String)] = [("Angola", "Angole"),
("Croatia", "Croatia"),
("Germany", "Germany"),
("Ireland", "Ireland"),
("Spain", "Spain"),
("United Kingdom", "United Kingdom"),
("Venezuela", "Venezuela")]
self.checkboxDialogViewController = CheckboxDialogViewController()
self.checkboxDialogViewController.titleDialog = "Countries"
self.checkboxDialogViewController.tableData = tableData
self.checkboxDialogViewController.defaultValues = [tableData[3]]
self.checkboxDialogViewController.componentName = DialogCheckboxViewEnum.countries
self.checkboxDialogViewController.delegateDialogTableView = self
self.checkboxDialogViewController.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
self.present(self.checkboxDialogViewController, animated: false, completion: nil)
}
func onCheckboxPickerValueChange(_ component: DialogCheckboxViewEnum, values: TranslationDictionary) {
print(component)
print(values)
}
}
示例项目
此仓库包含一个示例项目。要运行此示例项目,请先克隆仓库,然后从示例目录运行 pod install
。
作者
Kristijan Kontus, [email protected]
许可
SwiftCheckboxDialog 可在 MIT 许可证下获取。查阅 LICENSE 文件获取更多信息。