一个非常强大的 iOS 消息通知和 AlertView 扩展。可以从屏幕顶部、底部和中间快速弹出通知。您可以根据个人喜好自定义弹出视图。
##特性
将 FFToast 文件夹添加到您的项目中
##使用方法
#import <FFToast/FFToast.h>
您可以通过以下方法创建默认效果在顶部显示的消息通知:
/**
Create and display one Toast
@param title Message title
@param message Message content
@param iconImage Message icon, when toastType is not FFToastTypeDefault iconImage is empty will still have the corresponding icon
@param duration Show duration
*/
+ (void)showToastWithTitle:(NSString *)title message:(NSString *)message iconImage:(UIImage*)iconImage duration:(NSTimeInterval)duration toastType:(FFToastType)toastType;
其中 toastType
typedef NS_ENUM(NSInteger, FFToastType) {
//Gray background, no icon
FFToastTypeDefault = 0,
//Green background + success icon
FFToastTypeSuccess = 1,
//Red background + error icon
FFToastTypeError = 2,
//Orange background + warning icon
FFToastTypeWarning = 3,
//Gray blue background + info icon
FFToastTypeInfo = 4,
};
例如
[FFToast showToastWithTitle:@"This is the title" message:@"Message content......." iconImage:[UIImage imageNamed:@"test"] duration:3 toastType:FFToastTypeDefault];
标题(title)、消息(message)、图标(iconImage)可为空,FFToast 将根据具体内容进行适配。
如果您想在状态栏下方、屏幕底部或屏幕中间显示消息,您可以设置一些属性以实现。设置显示位置
typedef NS_ENUM(NSInteger, FFToastPosition) {
//Displayed at the top of the screen
FFToastPositionDefault = 0,
//Is displayed below the status bar
FFToastPositionBelowStatusBar = 1,
//Displayed below the status bar + rounded corners + left and right margins
FFToastPositionBelowStatusBarWithFillet = 2,
//Displayed at the bottom of the screen
FFToastPositionBottom = 3,
//Displayed at the bottom of the screen + fillet
FFToastPositionBottomWithFillet = 4,
//Displayed in the middle of the screen
FFToastPositionCentre = 5,
//Displayed in the middle of the screen + fillet
FFToastPositionCentreWithFillet = 6
};
一些其他属性
//background color
@property (strong, nonatomic) UIColor* toastBackgroundColor;
//Toast title text color
@property (strong, nonatomic) UIColor* titleTextColor;
//Toast content text color
@property (strong, nonatomic) UIColor* messageTextColor;
//Toast title text font
@property (strong, nonatomic) UIFont* titleFont;
//Toast text font
@property (strong, nonatomic) UIFont* messageFont;
//Toast View fillet
@property(assign,nonatomic)CGFloat toastCornerRadius;
//Toast View Transparency
@property(assign,nonatomic)CGFloat toastAlpha;
//Toast shows the length of time
@property(assign,nonatomic)NSTimeInterval duration;
//Toast disappear animation is enabled
@property(assign,nonatomic)BOOL dismissToastAnimated;
//Toast display position
@property (assign, nonatomic) FFToastPosition toastPosition;
//Toast display type
@property (assign, nonatomic) FFToastType toastType;
//Whether it is automatically hidden. AutoDismiss, enableDismissBtn, dismissBtnImage The three properties are only valid for Toast that pops up from the center of the screen
@property(assign,nonatomic)BOOL autoDismiss;
//Whether the hidden button is displayed in the upper right corner
@property(assign,nonatomic)BOOL enableDismissBtn;
//Hide the button's icon
@property (strong, nonatomic) UIImage* dismissBtnImage;
设置完属性后,您可以调用以下方法来显示它
/**
Show a Toast
*/
- (void)show;
或:
/**
Show a Toast
@param handler Toast click callback
*/
- (void)show:(handler)handler;
例如:
FFToast *toast = [[FFToast alloc]initToastWithTitle:@"title" message:@"Message content......." iconImage:[UIImage imageNamed:@"fftoast_info"]];
toast.toastPosition = FFToastPositionBelowStatusBarWithFillet;
toast.toastBackgroundColor = [UIColor colorWithRed:75.f/255.f green:107.f/255.f blue:122.f/255.f alpha:1.f];
[toast show:^{
//Toast is called when clicked
}];//[toast show];
如果您想从中间自定义 Toast,您可以调用以下方法:
/**
Show a custom Toast in the middle
@param customToastView Customized ToastView
@param autoDismiss Whether it is automatically hidden
@param duration Display duration (autoDismiss = NO this parameter will be invalid)
@param enableDismissBtn Whether to show the hidden button
@param dismissBtnImage Hide button image (enableDismissBtn = NO this parameter will be invalid)
@return Toast
*/
- (instancetype)initCentreToastWithView:(UIView *)customToastView autoDismiss:(BOOL)autoDismiss duration:(NSTimeInterval)duration enableDismissBtn:(BOOL)enableDismissBtn dismissBtnImage:(UIImage*)dismissBtnImage;
从中间自定义 Toast 时,您可以将上面参数 autoDismiss 意外的参数设置为 NO。然后在您自定义 View 中适当的位置添加一个关闭按钮。要关闭从中间弹出的 Toast,您可以调用以下方法:
/**
Hide a Toast
*/
- (void)dismissCentreToast;
顶部,下拉弹出的 Toast 下面不能自定义视图,但图标图(iconImage)、标题、消息可以按需设置并可为空,最终的 Toast 将根据具体内容进行适配。
隐藏消息通知:默认 3 秒后自动消失,向上滑动弹出消息通知以通知它将消失
##关于
作者: imlifengfeng
WeiBo: @imlifengfeng
使用是在 MIT 许可下提供的。请参阅 LICENSE 以获取完整详细信息。
FFToast是一个非常强大的iOS消息通知和AlertView扩展。它可以很容易地从屏幕顶部、屏幕底部和屏幕中间弹出一个通知。你可以很容易地自定义弹出的View。
## 特点
将FFToast文件夹添加到项目中
## 使用方法
#import <FFToast/FFToast.h>
你可以通过调用下面的方法创建一个显示在顶部的默认效果的消息通知
/**
创建并显示一个Toast
@param title 标题
@param message 消息内容
@param iconImage 消息icon,toastType不为FFToastTypeDefault时iconImage为空仍然会有相应icon
@param duration 显示时长
*/
+ (void)showToastWithTitle:(NSString *)title message:(NSString *)message iconImage:(UIImage*)iconImage duration:(NSTimeInterval)duration toastType:(FFToastType)toastType;
其中的toastType
typedef NS_ENUM(NSInteger, FFToastType) {
//灰色背景、无图标
FFToastTypeDefault = 0,
//绿色背景+成功图标
FFToastTypeSuccess = 1,
//红色背景+错误图标
FFToastTypeError = 2,
//橙色背景+警告图标
FFToastTypeWarning = 3,
//灰蓝色背景+信息图标
FFToastTypeInfo = 4,
};
例如
[FFToast showToastWithTitle:@"标题" message:@"消息内容......." iconImage:[UIImage imageNamed:@"test"] duration:3 toastType:FFToastTypeDefault];
标题(title)、消息内容(message)、图标(iconImage)均可以为nil,FFToast会根据具体的内容进行自适应。
如果想在状态栏下方、屏幕下方或者屏幕中间显示消息通知,可以通过设置一些属性实现。设置显示位置
typedef NS_ENUM(NSInteger, FFToastPosition) {
//显示在屏幕顶部
FFToastPositionDefault = 0,
//显示在状态栏下方
FFToastPositionBelowStatusBar = 1,
//显示在状态栏下方+圆角+左右边距
FFToastPositionBelowStatusBarWithFillet = 2,
//显示在屏幕底部
FFToastPositionBottom = 3,
//显示在屏幕底部+圆角
FFToastPositionBottomWithFillet = 4,
//显示在屏幕中间
FFToastPositionCentre = 5,
//显示在屏幕中间+圆角
FFToastPositionCentreWithFillet = 6
};
其他的一些属性
//背景颜色
@property (strong, nonatomic) UIColor* toastBackgroundColor;
//Toast标题文字颜色
@property (strong, nonatomic) UIColor* titleTextColor;
//Toast内容文字颜色
@property (strong, nonatomic) UIColor* messageTextColor;
//Toast标题文字字体
@property (strong, nonatomic) UIFont* titleFont;
//Toast文字字体
@property (strong, nonatomic) UIFont* messageFont;
//Toast View圆角
@property(assign,nonatomic)CGFloat toastCornerRadius;
//Toast View透明度
@property(assign,nonatomic)CGFloat toastAlpha;
//Toast显示时长
@property(assign,nonatomic)NSTimeInterval duration;
//Toast消失动画是否启用
@property(assign,nonatomic)BOOL dismissToastAnimated;
//Toast显示位置
@property (assign, nonatomic) FFToastPosition toastPosition;
//Toast显示类型
@property (assign, nonatomic) FFToastType toastType;
//是否自动隐藏,autoDismiss、enableDismissBtn、dismissBtnImage三个属性仅对从屏幕中间弹出的Toast有效
@property(assign,nonatomic)BOOL autoDismiss;
//是否在右上角显示隐藏按钮
@property(assign,nonatomic)BOOL enableDismissBtn;
//隐藏按钮的图标
@property (strong, nonatomic) UIImage* dismissBtnImage;
设置完属性后,就可以调用下面方法将其显示出来
/**
显示一个Toast
*/
- (void)show;
或者:
/**
显示一个Toast
@param handler Toast点击回调
*/
- (void)show:(handler)handler;
例如:
FFToast *toast = [[FFToast alloc]initToastWithTitle:@"标题" message:@"消息内容......." iconImage:[UIImage imageNamed:@"fftoast_info"]];
toast.toastPosition = FFToastPositionBelowStatusBarWithFillet;
toast.toastBackgroundColor = [UIColor colorWithRed:75.f/255.f green:107.f/255.f blue:122.f/255.f alpha:1.f];
[toast show:^{
//点击消息通知时调用
}];//[toast show];
如果你想自定义一个从中间弹出的Toast,可以调用下面的方法:
/**
在中间显示一个自定义Toast
@param customToastView 自定义的ToastView
@param autoDismiss 是否自动隐藏
@param duration 显示时长(autoDismiss = NO时该参数将无效)
@param enableDismissBtn 是否显示隐藏按钮
@param dismissBtnImage 隐藏按钮图片(enableDismissBtn = NO时该参数将无效)
@return Toast
*/
- (instancetype)initCentreToastWithView:(UIView *)customToastView autoDismiss:(BOOL)autoDismiss duration:(NSTimeInterval)duration enableDismissBtn:(BOOL)enableDismissBtn dismissBtnImage:(UIImage*)dismissBtnImage;
你在自定义从中间弹出的Toast时,你可以将上面的参数autoDismiss和参数enableDismissBtn设为NO。然后在你自定义的View中自己在合适的位置添加一个关闭按钮。关闭从中间弹出的Toast,可以调用下面的方法:
/**
隐藏一个Toast
*/
- (void)dismissCentreToast;
顶部、底部弹出的Toast不可自定义View,但是对于iconImage、Title、message均可以根据需要设置并且可以为nil,最终Toast会根据具体的内容进行自适应。
隐藏消息通知:默认3秒后自动消失,向上滑动弹出的消息通知它也会消失。
## 关于
作者: imlifengfeng
微博: @imlifengfeng