This is a simple extension of an iOS message notifications that can be used to pop up a prompt at the top or bottom of the screen. You can customize it according to their own display.

English instructions

Features

  • Easy to use
  • Can be easily customized

CocoaPods

To install FFToast using CocoaPods, please integrate it in your existing Podfile, or create a new Podfile:

target 'MyApp' do
  pod 'FFToast'
endCopy the code

Then run pod install.

Usage

#import <FFToast/FFToast.h>Copy the code

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;Copy the code

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};Copy the code

for example:

[FFToast showToastWithTitle:@"This is the title" message:@"Message content......." iconImage:[UIImage imageNamed:@"test"] duration:3 toastType:FFToastTypeDefault];Copy the code

Title (title), message (message), icon (iconImage) can be empty, FFToast will be based on specific content to adapt.

If you want to show a message notification below the status bar or below the screen, you can set some properties. Set the display position:

typedef NS_ENUM(NSInteger, FFToastPosition) {

    //Displayed at the top of the screen
    FFToastPositionDefault = 0.//Displayed below the status bar
    FFToastPositionBelowStatusBar = 1.//Displayed below the status bar + rounded corners + left and right margins
    FFToastPositionBelowStatusBarWithFillet = 2.//Displayed in the bottom of the screen
    FFToastPositionBottom = 3.//Displayed in the bottom of the screen + rounded
    FFToastPositionBottomWithFillet = 4

};Copy the code

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 corner radius
@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;Copy the code

After setting the properties, you can call the following method to display it:

/ **
 Show a Toast
 * /
- (void)show;Copy the code

or:

/ **
 Show a Toast

 @param handler Toast click callback
 * /
- (void)show:(handler)handler;Copy the code

for example:

FFToast *toast = [[FFToast alloc]initToastWithTitle:@"This is the 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:^ {//Called when you click message notifications
}];//[toast show];Copy the code

Hide the message notifications: The default 3 seconds after the automatic disappear, slide up the pop-up message to inform it will disappear

License

Usage is provided under the MIT License. See LICENSE for full details.

Chinese Instructions

The characteristics of

  • Simple and easy to use
  • It can be easily customized

CocoaPods

To install FFToast using CocoaPods, integrate it into your existing Podfile or create a new Podfile:

target 'MyApp' do
  pod 'FFToast'
endCopy the code

Then the pod install.

Method of use

#import <FFToast/FFToast.h>Copy the code

You can create a message notification with the default effect displayed at the top by calling the following method:

/ **
Create and display a Toast

@ param title title
@param message Message content
@param iconImage Message icon. If toastType is not FFToastTypeDefault, the corresponding icon will still be displayed if iconImage is empty
@param duration Indicates the duration
 * /
+ (void)showToastWithTitle:(NSString *)title message:(NSString *)message iconImage:(UIImage*)iconImage duration:(NSTimeInterval)duration toastType:(FFToastType)toastType;Copy the code

The 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};Copy the code

Such as:

[FFToast showToastWithTitle:@"The title" message:@"Message content......." iconImage:[UIImage imageNamed:@"test"] duration:3 toastType:FFToastTypeDefault];Copy the code

Title, message and iconImage can all be empty. FFToast ADAPTS to the specific content.

If you want to display a message notification at the bottom of the status bar or at the bottom of the screen, you can set some properties to do so. Set the display position:

typedef NS_ENUM(NSInteger, FFToastPosition) {

    //It appears at the top of the screen
    FFToastPositionDefault = 0.//It is displayed below the status bar
    FFToastPositionBelowStatusBar = 1.//Display below status bar + rounded corner + left and right margins
    FFToastPositionBelowStatusBarWithFillet = 2.//It appears at the bottom of the screen
    FFToastPositionBottom = 3.//Display at the bottom of the screen + rounded corner
    FFToastPositionBottomWithFillet = 4

};Copy the code

Some other properties:

//The background color
@property (strong, nonatomic) UIColor* toastBackgroundColor;
//Toast title text color
@property (strong, nonatomic) UIColor* titleTextColor;
//Text color
@property (strong, nonatomic) UIColor* messageTextColor;

//Toast title font
@property (strong, nonatomic) UIFont* titleFont;
//Toast text font
@property (strong, nonatomic) UIFont* messageFont;

//Toast the View rounded corners
@property(assign,nonatomic)CGFloat toastCornerRadius;
//Toast View transparency
@property(assign,nonatomic)CGFloat toastAlpha;

//Toast display duration
@property(assign,nonatomic)NSTimeInterval duration;
//Whether the Toast disappear animation is enabled
@property(assign,nonatomic)BOOL dismissToastAnimated;

//Toast indicates location
@property (assign, nonatomic) FFToastPosition toastPosition;Copy the code

Once the property is set, you can call the following method to display it:

/ **
Display a Toast
 * /
- (void)show;Copy the code

Or:

/ **
Display a Toast

@param Handler Toast Click callback
 * /
- (void)show:(handler)handler;Copy the code

Such as:

FFToast *toast = [[FFToast alloc]initToastWithTitle:@"The 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:^ {//Called when a message notification is clicked
}];//[toast show];Copy the code

Hidden message notification: it will disappear after 3 seconds by default. If you swipe up, the message notification will also disappear.

The license

This project is used under an MIT license. For more information, see LICENSE.