Just My Life & My Work

當使用者觸發了某個事件,通常會想要知道程式發生什麼事,此時程式就必須適時給予回應,Toast機制就應運而生。

iOS的SDK中並沒有ToastView,但開發者取經自Android的SDK,便寫出了ToastView API,讓需要的開發者可以直接取用!

比起AlertView,ToastView更加有彈性,因為不用再去觸碰OK確認,而且可設定延遲時間,甚至還可以塞進圖片,淡出淡入的動畫會讓使用者感到親切呢!

我從GitHub找到一個我很喜歡的ToastView API,在此稍微介紹它如何使用及特色~

使用例子


// basic usage
[self.view makeToast:@"This is a piece of HappyMan."];

// toast with duration, title, and position
[self.view makeToast:@"This is a piece of HappyMan with a title."
             duration:3.0
             position:@"top"
                title:@"HappyMan Title"];

// toast with an image
[self.view makeToast:@"This is a piece of HappyMan with an image."
            duration:3.0
            position:[NSValue valueWithCGPoint:CGPointMake(110, 110)]
               image:[UIImage imageNamed:@"HappyMan.png"]];

// display toast with an activity spinner
[self.view makeToastActivity];

加入專案步驟

  1. Add Toast+UIView.h & Toast+UIView.m to your project.
  2. Link against QuartzCore.
  3. If you’re using ARC, you’ll need to add the -fno-objc-arc compiler flag to Toast+UIView.m.

實機截圖

ToastView0

我們來demo七項功能~

ToastView7

Show Activity

ToastView6

Show an image view as toast at point (110, 110)

ToastView5

Show a custom view as toast

ToastView4

Make toast with an image & title

ToastView3

Make toast with an image

ToastView2

Make toast with a title

ToastView1

Make toast

原本團隊用的ToastView,很神奇地在iOS 6.0之後就無法顯示,只好另尋高明,很幸運地找到更好的效果~

Toast其實是吐司的意思,所以作者才會以吐司當作例子顯示,可真是有趣:P

參考:Toast · GitHub。

隨意留個言吧:)~

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料

標籤雲