5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

(swift)Loafで、サクッとエラーメッセージを表示する

Last updated at Posted at 2020-01-15

#Loafって?
(実装例)
20200116_021428.GIF

Inspired by Android's Toast,
Loaf is a Swifty Framework for Easy iOS Toasts
(引用: https://github.com/schmidyy/Loaf)

つまり、
ios版のAndroid's Toastのようです。

ちなみに、Android's Toastとは、以下です。

トーストは、操作に関する簡単なフィードバックを小さなポップアップに表示します。 トーストでは、メッセージの表示に必要なスペースのみを使用します。現在のアクティビティは表示されたままになり、引き続き操作することができます。トーストはタイムアウト後に自動的に消えます。
(引用: https://developer.android.com/guide/topics/ui/notifiers/toasts?hl=ja)!

Loafを使うことで、超カンタンにエラーメッセージやアラートなどを実装することができます。

#Loafの使い方
Cocoapods
まず、pod 'Loaf'を追加して、pod installしてください。

そして、以下のコードを記述してください。

Loaf("メッセージを表示", sender: self).show()

以上です。(カンタンスギ)

#応用
####スタイルをカスタマイズする(実装例)

//アイコンのイメージを指定する(今回は、postクラスのphoto(UIImage)を使用しました。)
let image = self.post.photo

Loaf("\(self.post.name)のポストを編集しました。", 
      //.customを指定し、背景色にsystemGreenとアイコンにimageを指定する
      state: .custom(.init(backgroundColor: .systemGreen, icon: image)), 
      location: .top, presentingDirection: .vertical, dismissingDirection: .vertical, sender: self).show()

実行結果↓
20200116_021515.GIF

#引用(スペシャルサンクス)

5
1
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
5
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?