Swift简单的AlertView
- iOS9.0+
- Xcode9.0+
- Swift4.0+
通过cocoaPods将KAlertViewController集成到你的项目中,首先要确保你已经安装了cocoaPods,然后执行
$pod init
配置podfile
文件
target 'TargetName' do
pod 'KAlertViewController'
end
配置完成后执行
$pod install
let alertView = KAlertView(title: "KAlertView", message: "Warmly celebrate the completion of KAlertView creation")
alertView.add(action: KalertAction(title: "取消", style: .cancel, handler: { (action) in
print(action.title)
}))
//MARK: - 注意循环引用
alertView.add(action: KalertAction(title: "确定", style: .destructive, handler: { [unowned alertView] (action) in
print(action.title)
for textField in alertView.textFields {
print(textField.text ?? "")
}
}))
alertView.addTextField { (textField) in
textField.placeholder = "请输入账号"
}
alertView.addTextField { (textField) in
textField.placeholder = "请输入密码"
}
let alertVC = KAlertController(alertView: alertView, preferredStyle: .alert)
alertVC.backgoundTapDismissEnable = true
present(alertVC, animated: true, completion: nil)