LoginSignup
12
13

More than 5 years have passed since last update.

UIAlertControllerをシンプルに使えるライブラリを公開しました

Last updated at Posted at 2015-07-15

先日、UIAlertControllerを簡単に使えるライブラリを公開しました。

Kamagari : Simple UIAlertController builder class in Swift
https://github.com/tasanobu/Kamagari

iOS9がリリースされる今年の秋には、iOS7のサポートを終了するプロジェクトが増えてくると思います。
UIAlertViewやUIActionSheet を置き換える際には、ぜひこのライブラリの導入を検討してもらえると嬉しいです。

では、機能や使い方を説明します。

機能

このライブラリの機能は次の2つです。

  • UIAlertControllerをBuilderパターンで簡単に作れる AlertBuilder クラス
  • UIAlertController を簡単にモーダル表示できる UIAlertController のextension メソッド

利用例

以下のサンプルコードです。
UIAlertControllerをメソッドチェーンで作って、そのまま表示することができます。

Alert
AlertBuilder(title: "Question", message: "Are you sure where Kamagari is?", preferredStyle: .Alert)
    .addAction(title: "NO", style: .Cancel) { _ in }
    .addAction(title: "YES", style: .Default) { _ in }
    .build()
    .kam_show(animated: true)

ActionSheet
// ActionSheet Sample
if UIDevice.currentDevice().userInterfaceIdiom != .Pad {
    // iPhone
    AlertBuilder(title: "Question", message: "Are you sure where Kamagari is?", preferredStyle: .ActionSheet)
        .addAction(title: "NO", style: .Cancel) { _ in }
        .addAction(title: "YES", style: .Default) { _ in }
        .build()
        .kam_show(animated: true)
} else {
    // iPad
    // setPopoverPresentationProperties()を使って
    // UIPopoverPresentationController の各種プロパティを設定できます
    AlertBuilder(title: "Question", message: "Are you sure where Kamagari is?", preferredStyle: .ActionSheet)
        .addAction(title: "YES", style: .Default) { _ in }
        .addAction(title: "Not Sure", style: .Default) { _ in }
        .setPopoverPresentationProperties(sourceView: view, sourceRect: CGRectMake(0, 0, 100, 100), barButtonItem: nil, permittedArrowDirections: .Any)
        .build()
        .kam_show(animated: true)
}

システム要件

  • iOS 8.0+
  • Xcode 6.3

インストール方法

Cocoapodsを使うと簡単にインストールできます。
Podfileで このライブラリ(Kamagari) を追加し、pod install or pod update を実行して下さい。

platform :ios, '8.0'
use_frameworks!

pod 'Kamagari'

ご意見、ご要望などあれば、可能な限り対応しようと考えております。
Issueなりプルリクエストなり頂けると幸いです。

Kamagari : Simple UIAlertController builder class in Swift
https://github.com/tasanobu/Kamagari

12
13
3

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
12
13