LoginSignup
31
25

More than 5 years have passed since last update.

オシャレなアラートを使用できる「SweetAlert-iOS」の使い方

Last updated at Posted at 2015-12-15

オシャレなアラートを簡単に作ることのできる「SweetAlert-iOS」の使い方を紹介します。
元ソースはGithubで公開されてます。

alert5.gif

導入方法

Githubからソースコードをダウンロードしてフォルダの中にある「SweetAlert.swift」を自分のxcodeプロジェクトの中にコピーします。コピーが完了したらすぐに使いはじめることが出来ます。

スクリーンショット 2015-12-15 22.45.56.png

スクリーンショット 2015-12-15 22.46.17.png

使い方

タイトルとボタンのみ

SweetAlert().showAlert("メッセージ!")

alert1.gif

タイトルとテキストとボタン

SweetAlert().showAlert("タイトル", subTitle: "メッセージ内容", style: AlertStyle.None)

alert2.gif

成功アラート

SweetAlert().showAlert("Good job!", subTitle: "良く出来ました!", style: AlertStyle.Success)

alert3.gif

ボタンが2つあるアラート

SweetAlert().showAlert("Are you sure?", subTitle: "削除してもよろしいですか?", style: AlertStyle.Warning, buttonTitle:"いいえ", buttonColor:UIColor.redColor() , otherButtonTitle:  "はい", otherButtonColor:UIColor.redColor()) { (isOtherButton) -> Void in
            if isOtherButton == true {

                //「いいえ」を選択した時の処理

            }
            else {

                //「はい」を選択した時の処理
                SweetAlert().showAlert("成功!", subTitle: "削除が成功しました!", style: AlertStyle.Success)
            }
        }

alert4.gif

ボタンが2つあるアラート(2)

SweetAlert().showAlert("Are you sure?", subTitle: "削除してもよろしいですか?", style: AlertStyle.Warning, buttonTitle:"いいえ", buttonColor:UIColor.redColor() , otherButtonTitle:  "はい", otherButtonColor: UIColor.redColor()) { (isOtherButton) -> Void in
            if isOtherButton == true {

                //「いいえ」を選択した時の処理
                SweetAlert().showAlert("Cancelled!", subTitle: "削除をキャンセルしました", style: AlertStyle.Error)
            }
            else {

                //「はい」を選択した時の処理
                SweetAlert().showAlert("Deleted!", subTitle: "削除が完了しました!", style: AlertStyle.Success)
            }
        }

alert5.gif

31
25
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
31
25