當使用者觸發了某個事件,通常會想要知道程式發生什麼事,此時程式就必須適時給予回應,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];
加入專案步驟
- Add
Toast+UIView.h&Toast+UIView.mto your project. - Link against QuartzCore.
- If you’re using ARC, you’ll need to add the
-fno-objc-arccompiler flag toToast+UIView.m.
實機截圖
原本團隊用的ToastView,很神奇地在iOS 6.0之後就無法顯示,只好另尋高明,很幸運地找到更好的效果~
Toast其實是吐司的意思,所以作者才會以吐司當作例子顯示,可真是有趣:P
參考:Toast · GitHub。








隨意留個言吧:)~