LWAlert
特性
- HUD
- alert
- picker
- 使用指定行自定义组件
要求
-
Xcode 9.0+
-
Swift 4.2+
Swift 4.0 使用标签 0.1.1,但存在保留循环问题。
安装
CocoaPods
-
将
pod 'LWAlert'
添加到您的Podfile中。 -
运行
pod install
或pod update
。
手动
-
下载或克隆此仓库。
-
将
LWAlert
文件夹拖入您的项目。
使用
@IBAction func buttonAction(_ sender: UIButton) {
var alert: LWAlert
if sender.tag == 0 {//hud
// alert = LWAlert.init(title: "this is title", message: "this is message this is message this is message this is message this is message this is message this is message this is message ", style: .hud)
LWAlert.showHUD(title: "this is title", message: "this is message this is message this is message this is message this is message this is message this is message this is message")
return
} else if sender.tag == 1{
alert = LWAlert.init(title: "this is title", message: "this is message this is message this is message this is message this is message this is message this is message this is message ", style: .alert)
alert.addButton(LWAlertButton.init(title: "Cancel", handler: nil))
alert.addButton(LWAlertButton.init(title: "Confirm", handler: { ( button ) in
print("confirm")
//Don't worry about retain cycle
//print(alert.buttons.count)
}))
} else if sender.tag == 2 {//datePicker
alert = LWAlert.init(style: .datePicker)
alert.dateInfoBlock = { info in
print(info.date)
}
} else if sender.tag == 3 {//timePicker
alert = LWAlert.init(style: .timePicker)
alert.dateInfoBlock = { info in
print(info.time)
}
}else if sender.tag == 4 {//systemDatePicker
alert = LWAlert.init(style: .systemDatePicker)
alert.dateInfoBlock = { info in
print(info.date)
}
}else if sender.tag == 5{//everyThirtyIn24Hours
alert = LWAlert.init(style: .everyThirtyIn24Hours)
alert.dateInfoBlock = { info in
print(info.time)
}
}else if sender.tag == 6{//custom Picker with 1 component
alert = LWAlert.init(customData: [["One", "Two", "Three", "Four", "Five"]])
alert.customPickerBlock = { str in
print(str)
}
}else{////custom Picker with 2 components
// alert = LWAlert.init(customData: [["One", "Two", "Three", "Four", "Five"], ["O", "T", "F"]], defaultStrings: ["NotExsit", "T"])
alert = LWAlert.init(customData: [["One", "Two", "Three", "Four", "Five"], ["O", "T", "F"]])
alert.customPickerBlock = { str in
print(str)
}
}
alert.show()
}
授权
LWAlert 在 MIT 许可下提供。有关详细信息,请参阅 LICENSE 文件。