A C#/Xamarin based implementation of the Android Snackbar for iOS.
TTGSnackbar is useful for showing a brief message at the bottom of the screen with an action button.
It appears above all other elements on screen and only one can be displayed at a time.
It disappears after a timeout or after user click the action button.
iOS 8+
var snackbar = new TTGSnackbar("Message", TTGSnackbarDuration.Short);
snackbar.Show();
var snackbar = new TTGSnackbar("Message", TTGSnackbarDuration.Long, "Cancel", () => { Console.WriteLine("clicked");});
snackbar.Show();
var snackbar = new TTGSnackbar("Message", TTGSnackbarDuration.Forever, "Cancel", async (s) => {
await Task.Delay(3000);
s.dismiss();
});
snackbar.Show();
var snackbar = new TTGSnackbar("Message", TTGSnackbarDuration.Middle);
// Action 1
snackbar.ActionText = "Yes";
snackbar.ActionTextColor = UIColor.Green;
snackbar.ActionBlock = (t) => { Console.WriteLine("clicked yes"); };
// Action 2
snackbar.SecondActionText = "No";
snackbar.SecondActionTextColor = UIColor.Purple;
snackbar.SecondActionBlock = (t) => { Console.WriteLine("clicked no"); };
snackbar.Show();
message: String
defines the message to diaplay.
messageTextColor: UIColor
defines the message text color.
messageTextFont: UIFont
defines the message text font.
duration: TTGSnackbarDuration
defines the display duration.
TTGSnackbarDuration
: Short
, Middle
, Long
and Forever
.
When you set Forever
, the snackbar will show an activity indicator after user click the action button and you must dismiss the snackbar manually.
actionText: String
defines the action button title.
actionTextColor: UIColor
defines the action button title color.
actionTextFont: UIFont
defines the action button title font.
actionBlock: TTGActionBlock?
will be called when user click the action button.
// TTGActionBlock definition.
public Action<TTGSnackbar> ActionBlock
secondActionText: String
secondActionTextColor: UIColor
secondActionTextFont: UIFont
secondActionBlock: TTGActionBlock?
dismissBlock: TTGDismissBlock?
will be called when snackbar dismiss automatically or when user click action button to dismiss the snackbar.
// TTGDismissBlock definition.
public typealias TTGDismissBlock = (snackbar: TTGSnackbar) -> Void
animationType: TTGSnackbarAnimationType
defines the style of snackbar when it show and dismiss.
TTGSnackbarAnimationType
: FadeInFadeOut
, SlideFromBottomToTop
, SlideFromBottomBackToBottom
, SlideFromLeftToRight
, SlideFromRightToLeft
and Flip
.
The default value of animationType
is SlideFromBottomBackToBottom
, which is the same as Snackbar in Android.
animationDuration: NSTimeInterval
defines the duration of show and hide animation.
leftMargin: CGFloat
, rightMargin: CGFloat
and bottomMargin: CGFloat
define the margins of snackbar.
height: CGFloat
defines the height of snackbar.
cornerRadius: CGFloat
defines the corner radius of snackbar.
This is a port of https://github.com/zekunyan/TTGSnackbar/. All credits go to zekunynan.