Coder Social home page Coder Social logo

whtoast's Introduction

WHToast

WHToast是一个轻量级的提示控件,没有任何依赖。先来看一下效果图。

whtoast.gif

使用方法也非常简单,下面是使用步骤。

1. 可以直接在本页面下载文件拖入WHToast文件到工程,也可以使用pod。

如果pod找不到WHToast,先执行 pod setup

pod 'WHToast','~>0.0.2'

// 如果pod找不到WHToast,先执行 pod setup
pod setup

2. 导入WHToast.h头文件

// pod
#import <WHToast.h>
// 直接拖入文件
#import "WHToast.h"

3. 说明

每种显示类型都有两个方法,第一个方法默认显示在屏幕中间,第二个方法带有originY参数的是可以自定义显示位置,也就是自定义frame.origin.y。(注意:如果传入的originY<=0,也是显示在屏幕中间)。

4. 显示文字提示。

// 显示在页面中间,duration代表多久之后消失
[WHToast showMessage:@"测试一下" duration:2 finishHandler:^{
  NSLog(@"省略n行代码");
}];

// 自定义frame.origin.y
[WHToast showMessage:@"测试一下" originY:200 duration:2 finishHandler:^{
  NSLog(@"省略n行代码");
}];

5. 显示带有成功图标的提示。

// 显示在页面中间,duration代表多久之后消失
[WHToast showSuccessWithMessage:@"测试一下" duration:2 finishHandler:^{
  NSLog(@"省略n行代码");
}];

// 自定义frame.origin.y
[WHToast showSuccessWithMessage:@"测试一下" originY:100 duration:2 finishHandler:^{
  NSLog(@"省略n行代码");
}];

6. 带有错误图标的提示。

// 显示在页面中间,duration代表多久之后消失
[WHToast showErrorWithMessage:@"测试一下" duration:2 finishHandler:^{
  NSLog(@"省略n行代码");
}];

// 自定义frame.origin.y
[WHToast showErrorWithMessage:@"测试一下" originY:200 duration
:2 finishHandler:^{
  NSLog(@"省略n行代码");
}];

7. 传入一个图片,自定义图标提示。

// 显示自定义图片,如果message传入nil,则只显示图片,duration代表多久之后消失
[WHToast showImage:[UIImage imageNamed:@"123"] message:nil duration:2 finishHandler:^{
  NSLog(@"省略n行代码");
}];

// 自定义frame.origin.y,显示自定义图片
[WHToast showImage:[UIImage imageNamed:@"123"] message:@"测试一下" originY:200 duration:2 finishHandler:^{
  NSLog(@"省略n行代码");
}];

8. 全局自定义显示样式。

直接使用WHToast的类方法就可以做全局自定义设置。样式如下。

/** 是否有背景遮罩,默认有 */
+ (void)setShowMask:(BOOL)showMask;

/** 遮罩颜色,默认透明 */
+ (void)setMaskColor:(UIColor *)maskColor;

/** 遮罩是否遮住导航栏,默认遮住 */
+ (void)setMaskCoverNav:(BOOL)maskCoverNav;

/** 边距,默认12 */
+ (void)setPadding:(CGFloat)padding;

/** 提示图片尺寸,默认(25,25)*/
+ (void)setTipImageSize:(CGSize)tipImageSize;

/** 圆角,默认7 */
+ (void)setCornerRadius:(CGFloat)cornerRadius;

/** 背景颜色,默认[UIColor colorWithWhite:0 alpha:0.8] */
+ (void)setBackColor:(UIColor *)backColor;

/** 成功/失败 图标颜色,默认白色 */
+ (void)setIconColor:(UIColor *)iconColor;

/** 文字颜色,默认白色 */
+ (void)setTextColor:(UIColor *)textColor;

/** 文字大小,默认15 */
+ (void)setFontSize:(CGFloat)fontSize;

/** 恢复默认配置 */
+ (void)resetConfig;

// 调用方式
[WHToast setShowMask:NO];
[WHToast setMaskColor:[UIColor colorWithWhite:0 alpha:0.6]];
[WHToast setMaskCoverNav:NO];
[WHToast setTipImageSize:CGSizeMake(50, 50)];
[WHToast setFontSize:30];
[WHToast setPadding:20];
[WHToast setCornerRadius:20];
[WHToast setIconColor:[UIColor blackColor]];
[WHToast setBackColor:[UIColor whiteColor]];
[WHToast setTextColor:[UIColor blackColor]];

9. 下面贴出来WHToast的所有方法。

/** 仅文字,展示在屏幕中间 */
+ (void)showMessage:(NSString *)message duration:(NSTimeInterval)duration finishHandler:(dispatch_block_t)handler;

/** 仅文字,自定义frame.origin.y 如果(originY <= 0)会展示在屏幕中间 */
+ (void)showMessage:(NSString *)message originY:(CGFloat)originY duration:(NSTimeInterval)duration finishHandler:(dispatch_block_t)handler;

/** 成功图标和文字,展示在屏幕中间 */
+ (void)showSuccessWithMessage:(NSString *)message duration:(NSTimeInterval)duration finishHandler:(dispatch_block_t)handler;

/** 成功图标和文字,自定义frame.origin.y 如果(originY <= 0)会展示在屏幕中间 */
+ (void)showSuccessWithMessage:(NSString *)message originY:(CGFloat)originY duration:(NSTimeInterval)duration finishHandler:(dispatch_block_t)handler;

/** 失败图标和文字,展示在屏幕中间 */
+ (void)showErrorWithMessage:(NSString *)message duration:(NSTimeInterval)duration finishHandler:(dispatch_block_t)handler;

/** 失败图标和文字,自定义frame.origin.y 如果(originY <= 0)会展示在屏幕中间 */
+ (void)showErrorWithMessage:(NSString *)message originY:(CGFloat)originY duration:(NSTimeInterval)duration finishHandler:(dispatch_block_t)handler;

/** 自定义图片和文字,展示在屏幕中间。 如果message传入nil,则只显示图片 */
+ (void)showImage:(UIImage *)image message:(NSString *)message duration:(NSTimeInterval)duration finishHandler:(dispatch_block_t)handler;

/** 自定义图片和文字,自定义frame.origin.y 如果(originY <= 0)会展示在屏幕中间。如果message传入nil,则只显示图片 */
+ (void)showImage:(UIImage *)image message:(NSString *)message originY:(CGFloat)originY duration:(NSTimeInterval)duration finishHandler:(dispatch_block_t)handler;

/** 主动消失 */
+ (void)hide;


/******************************************************/
/******************  设置全局样式  **********************/
/******************************************************/

/** 是否有背景遮罩,默认有 */
+ (void)setShowMask:(BOOL)showMask;

/** 遮罩颜色,默认透明 */
+ (void)setMaskColor:(UIColor *)maskColor;

/** 遮罩是否遮住导航栏,默认遮住 */
+ (void)setMaskCoverNav:(BOOL)maskCoverNav;

/** 边距,默认12 */
+ (void)setPadding:(CGFloat)padding;

/** 提示图片尺寸,默认(25,25)*/
+ (void)setTipImageSize:(CGSize)tipImageSize;

/** 圆角,默认7 */
+ (void)setCornerRadius:(CGFloat)cornerRadius;

/** 背景颜色,默认[UIColor colorWithWhite:0 alpha:0.8] */
+ (void)setBackColor:(UIColor *)backColor;

/** 成功/失败 图标颜色,默认白色 */
+ (void)setIconColor:(UIColor *)iconColor;

/** 文字颜色,默认白色 */
+ (void)setTextColor:(UIColor *)textColor;

/** 文字大小,默认15 */
+ (void)setFontSize:(CGFloat)fontSize;

/** 恢复默认配置 */
+ (void)resetConfig;

whtoast's People

Contributors

remember17 avatar

Watchers

James Cloos avatar swift avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.