2016-08-24 47 views
-1

Swift言語を使用してプログラムでカスタムアラートをプログラムで実装する必要があります。私はいくつかのサードパーティ製ライブラリ "SCLAlertView"を使用して実装しようとしましたが、それから理解することができません、私は簡単なアラートのポップアップを動的メッセージとアプリケーションのボタンの数を変更する必要があります。私のアプリケーションにはたくさんのAlertViewがあったので。だから私は動的に更新する必要があります。Swiftでカスタムアラートビューを作成する方法

I以下

は私がこの機能を実装するために助けてください、それは

enter image description here

enter image description here

を実装するためにどのように見えるかをカスタムアラートのサンプル画像を添付しています。

+1

を使用するように簡単です、あなたのアラートに関するカスタムは何ですか?なぜあなたは通常の 'UIAlertController'を使用できませんか? ( 'UIAlertView'は非推奨です)。 – rmaddy

答えて

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) 

あなたは、動的に、ニーズに応じて、あなたのUIAlertControllerにUIAlertActionさんを追加することができます。 2つのボタンが必要な場合は、alertAction3を追加しないでください。 3つまたは4つ必要な場合は、必要に応じて追加します。

1

pod SCLAlertView

とインストールポッドた後、あなたはSCLAlertViewは、多くの対照群は、TextFieldを追加したいとしているこれらの列挙型で

enum SCLAlertViewStyle: Int { 
     case Success, Error, Notice, Warning, Info, Edit, Wait 
    } 

    public enum SCLAnimationStyle { 
     case NoAnimation, TopToBottom, BottomToTop, LeftToRight, RightToLeft 
    } 

Alert view StyleAlert View Animationスタイルを選択することができ、ここではボタンやアイコン

がありますボタン機能コードの追加

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") 
GitHubのページで

とアラートビューのカスタムタイプ

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 

あなたは多くの美しい最新デザインのアラートビューを見つけるだろう、

https://github.com/vikmeup/SCLAlertView-Swift

関連する問題