LoginSignup
19
19

More than 5 years have passed since last update.

[Swift] 簡単にエラーメッセージを表示する AlertBar

Last updated at Posted at 2016-01-09

概要

ステータスバーの上にエラーや完了通知メッセージを表示するAlertBarを作りました。
簡単なものですが、開発初期段階でデザインが決まってないときやモックなどで便利になるかと思います。

https://github.com/jinSasaki/AlertBar
気に入ったらStarお願いします。

demo

環境

  • Swift 2.0
  • iOS 8.0
  • ARC

CocoaPodsでインストール

(CocoaPodsのインストール方法は省略)
Podfileに以下を追加

pod "AlertBar"

使い方

はじめに

AlertBarをimport

import UIKit
import AlertBar

class ViewController: UIViewController {
...

メッセージを表示

AlertBarには

  • Success
  • Error
  • Notice
  • Warning
  • Info

タイプが用意してあります。
それぞれ予め文字色と背景色が設定されています。

メッセージを表示するときは

AlertBar.show(.Success, message: "This is a Success message.")

と書きます。

また、背景色と文字色を個別に設定することもできます。
Customタイプを設定し、背景色とと文字色を .Custom(BackgroundColor, TextColor)のように指定します。

AlertBar.show(.Custom(UIColor.lightGrayColor(), UIColor.blackColor()), message: "This is a Custom message.")

メッセージの表示時間

AlertBar はメッセージの表示時間も変更することができます。

AlertBar.show(.Success, message: "This is a Success message.", duration: 10)
19
19
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
19
19