FFToast

TAG:  Swift , FFToast , Toast , Custom Notification , Alert ,  Alert view , Custom Toast, ios , Notification

Licence:  MIT

Classification:  FFToast

Platform:  IOS

Language:  Swift

Device:
iPhone / iPad

Download

Installation

CocoaPods

To install FFToast using CocoaPods, please integrate it in your existing Podfile, or create a new Podfile:
target 'MyApp' do
  pod 'FFToast'
end
Then run pod install.

Manual

Add FFToast folder to your project

Usage

#import <FFToast/FFToast.h>
You can create a message notification that shows the default effect at the top by calling the following method:
/**
 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;
Where 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,
};
for example:
[FFToast showToastWithTitle:@"This is the title" message:@"Message content......." iconImage:[UIImage imageNamed:@"test"] duration:3 toastType:FFToastTypeDefault];
Title (title), message (message), icon (iconImage) can be empty, FFToast will be based on specific content to adapt.
If you want to show the message below the status bar, the bottom of the screen or the middle of the screen, you can set some properties to achieve. Set the display position:
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

};
Some other attributes:
//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;
After setting the properties, you can call the following method to display it:
/**
 Show a Toast
 */
- (void)show;
or:
/**
 Show a Toast

 @param handler Toast click callback
 */
- (void)show:(handler)handler;
E.g:
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];
If you want to customize a Toast from the middle, you can call the following method:
/**
 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;
When you customize Toast from the middle, you can set the above parameters autoDismiss and the parameter enableDismissBtn to NO. And then in your custom View in their own place in the appropriate place to add a close button. To close the Toast from the middle, you can call the following method:
/**
 Hide a Toast
 */
- (void)dismissCentreToast;
Top, the bottom of the pop-up Toast can not customize View, but for iconImage, Title, message can be set according to need and can be nil, the final Toast will be based on specific content to adapt.
Hide message notifications: The default 3 seconds after the automatic disappear, slide up the pop-up message to inform it will disappear

0 Comments: