我必须使用Swift语言以编程方式在我的应用程序中实现自定义警报。我尝试使用一些第三方库" SCLAlertView"但是无法从中理解,我需要一个工具简单的警报弹出窗口,其中包含动态消息和App中的按钮更改次数。因为我的应用程序中有很多AlertView。所以我需要动态更新。
下面我附上了自定义提醒的示例图片,了解它的实施方式
请帮我实现此功能。
答案 0 :(得分:1)
只要您愿意,就可以在UIAlertController上添加不同的UIAlertAction。
let alertAction: UIAlertAction = UIAlertAction(title: "YES", style: UIAlertActionStyle.Default, handler: {
//Code goes here
})
let alertAction2: UIAlertAction = UIAlertAction(title: "NO", style: UIAlertActionStyle.Default, handler: {
//Code goes here
})
let alertAction3: UIAlertAction = UIAlertAction(title: "Maybe", style: UIAlertActionStyle.Default, handler: {
//Code goes here
})
alert.addAction(alertAction)
alert.addAction(alertAction2)
alert.addAction(alertAction3)
您可以根据需要动态地将UIAlertAction添加到您的UIAlertController中。如果您只需要两个按钮,则不要添加alertAction3
。如果您需要三个或四个,请根据需要添加它们。
答案 1 :(得分:1)
安装包含pod SCLAlertView
您可以使用这些枚举选择Alert view Style
和Alert View Animation
样式
enum SCLAlertViewStyle: Int {
case Success, Error, Notice, Warning, Info, Edit, Wait
}
public enum SCLAnimationStyle {
case NoAnimation, TopToBottom, BottomToTop, LeftToRight, RightToLeft
}
SCLAlertView有许多控制组,如添加textField,按钮和图标
这是一个添加按钮功能代码
let alertView = SCLAlertView()
alertView.addButton("First Button", target:self, selector:Selector("firstButton"))
alertView.addButton("Second Button") {
println("Second button tapped")
}
alertView.showSuccess("Button View", subTitle: "This alert view has buttons")
和警报视图自定义类型
SCLAlertView().showError("Hello Error", subTitle: "This is a more descriptive error text.") // Error
SCLAlertView().showNotice("Hello Notice", subTitle: "This is a more descriptive notice text.") // Notice
SCLAlertView().showWarning("Hello Warning", subTitle: "This is a more descriptive warning text.") // Warning
SCLAlertView().showInfo("Hello Info", subTitle: "This is a more descriptive info text.") // Info
SCLAlertView().showEdit("Hello Edit", subTitle: "This is a more descriptive info text.") // Edit
在Github Page中你会发现许多美丽的设计警报视图,它很容易使用