我必須在我的應用程序中使用Swift語言以編程方式實現自定義警報。我嘗試使用一些第三方庫「SCLAlertView」來實現,但無法理解,我需要一個實現簡單的警報彈出式窗口,其中包含動態消息和App中按鈕數量的變化。由於我的應用程序中有很多AlertView。所以我需要動態更新。在Swift中如何創建自定義警報視圖
下面我附上定製警報的樣本圖像它的外觀實現
請幫我實現此功能。
我必須在我的應用程序中使用Swift語言以編程方式實現自定義警報。我嘗試使用一些第三方庫「SCLAlertView」來實現,但無法理解,我需要一個實現簡單的警報彈出式窗口,其中包含動態消息和App中按鈕數量的變化。由於我的應用程序中有很多AlertView。所以我需要動態更新。在Swift中如何創建自定義警報視圖
下面我附上定製警報的樣本圖像它的外觀實現
請幫我實現此功能。
只要您希望它添加到您的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
。如果您需要三到四個,則根據需要添加它們。
與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後有許多對照組喜歡添加文本框,按鈕和圖標
這裏是一個添加按鈕功能代碼
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的頁面上,你會發現許多beatiful德興警報的意見,很容易使用
什麼是你的警報習慣嗎?爲什麼你不能使用普通的'UIAlertController'? ('UIAlertView'已棄用)。 – rmaddy