WHToast is a lightweight prompt control with no dependencies. Github:github.com/remember17/…

Method of use

1. You can directly go to Github to download the file and drag it into the project, or you can use pod.

pod 'WHToast'
Copy the code

2. Import the whtoast. h header file

#import <WHToast.h>
Copy the code

3. The instructions

Each display type has two methods. The first method is displayed in the middle of the screen by default, and the second method, with an originY parameter, has a custom display position, that is, frame.origine.y. (Note: If originY<=0 is passed in, it is also displayed in the middle of the screen).

4. Display text prompts.

Duration is displayed in the middle of the page
[WHToast showMessage:@" Test it out" duration:2 finishHandler:^{
  NSLog(@" Omit n lines of code");
}];

// Customize frame.origine.y
[WHToast showMessage:@" Test it out" originY:200 duration:2 finishHandler:^{
  NSLog(@" Omit n lines of code");
}];
Copy the code

5. A message with a success icon is displayed.

Duration is displayed in the middle of the page
[WHToast showSuccessWithMessage:@" Test it out" duration:2 finishHandler:^{
  NSLog(@" Omit n lines of code");
}];

// Customize frame.origine.y
[WHToast showSuccessWithMessage:@" Test it out" originY:100 duration:2 finishHandler:^{
  NSLog(@" Omit n lines of code");
}];
Copy the code

6. Prompt with error icon.

Duration is displayed in the middle of the page
[WHToast showErrorWithMessage:@" Test it out" duration:2 finishHandler:^{
  NSLog(@" Omit n lines of code");
}];

// Customize frame.origine.y
[WHToast showErrorWithMessage:@" Test it out" originY:200 duration
:2 finishHandler:^{
  NSLog(@" Omit n lines of code");
}];
Copy the code

7. Pass in an image and customize the icon prompt.

// Display custom images, if message is passed nil, display only images, duration means how long to disappear
[WHToast showImage:[UIImage imageNamed:@ "123"] message:nil duration:2 finishHandler:^{
  NSLog(@" Omit n lines of code");
}];

// Create a custom frame. Origin. Y to display a custom picture
[WHToast showImage:[UIImage imageNamed:@ "123"] message:@" Test it out" originY:200 duration:2 finishHandler:^{
  NSLog(@" Omit n lines of code");
}];
Copy the code

8. Post belowWHToastAll the ways.


/** Only text, displayed in the middle of the screen */
+ (void)showMessage:(NSString *)message duration:(NSTimeInterval)duration finishHandler:(dispatch_block_t)handler;

/** Only text, custom frame.origin. Y if (originY <= 0) is displayed in the middle of the screen */
+ (void)showMessage:(NSString *)message originY:(CGFloat)originY duration:(NSTimeInterval)duration finishHandler:(dispatch_block_t)handler;

/** Success icon and text, displayed in the middle of the screen */
+ (void)showSuccessWithMessage:(NSString *)message duration:(NSTimeInterval)duration finishHandler:(dispatch_block_t)handler;

/** Success icon and text, custom frame.origine. y if (originY <= 0) will be displayed in the middle of the screen */
+ (void)showSuccessWithMessage:(NSString *)message originY:(CGFloat)originY duration:(NSTimeInterval)duration finishHandler:(dispatch_block_t)handler;

/** Failure icon and text, displayed in the middle of the screen */
+ (void)showErrorWithMessage:(NSString *)message duration:(NSTimeInterval)duration finishHandler:(dispatch_block_t)handler;

/** Failure icon and text, custom frame.origine. y if (originY <= 0) will be displayed in the middle of the screen */
+ (void)showErrorWithMessage:(NSString *)message originY:(CGFloat)originY duration:(NSTimeInterval)duration finishHandler:(dispatch_block_t)handler;

/** Custom image and text displayed in the middle of the screen. If message is passed nil, only pictures */ are displayed
+ (void)showImage:(UIImage *)image message:(NSString *)message duration:(NSTimeInterval)duration finishHandler:(dispatch_block_t)handler;

/** Custom image and text, custom frame.origin. Y if (originY <= 0) will be displayed in the middle of the screen. If message is passed nil, only pictures */ are displayed
+ (void)showImage:(UIImage *)image message:(NSString *)message originY:(CGFloat)originY duration:(NSTimeInterval)duration finishHandler:(dispatch_block_t)handler;

/** vanish */
+ (void)hide;


/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /
/ * * * * * * * * * * * * * * * * * * set the global style * * * * * * * * * * * * * * * * * * * * * * /
/ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /

/** Whether there is a background mask, the default is */
+ (void)setShowMask:(BOOL)showMask;

/** Mask color, default transparent */
+ (void)setMaskColor:(UIColor *)maskColor;

/** Whether the mask covers the navigation bar, the default cover */
+ (void)setMaskCoverNav:(BOOL)maskCoverNav;

/** Margin, default 12 */
+ (void)setPadding:(CGFloat)padding;

/** prompt image size, default (20,20) */
+ (void)setTipImageSize:(CGSize)tipImageSize;

/** toast rounded corners, default 7 */
+ (void)setCornerRadius:(CGFloat)cornerRadius;

/** indicates rounded corners. Default is 0 */
+ (void)setImageCornerRadius:(CGFloat)cornerRadius;

/** Background color, default [UIColor colorWithWhite:0 alpha:0.8] */
+ (void)setBackColor:(UIColor *)backColor;

/** Success/failure icon color, white */ by default
+ (void)setIconColor:(UIColor *)iconColor;

/** Text color, white */ by default
+ (void)setTextColor:(UIColor *)textColor;

/** Text size, default 15 */
+ (void)setFontSize:(CGFloat)fontSize;

/** Restore the default configuration */
+ (void)resetConfig;

Copy the code