取代你的Toast-->SCPromptView

SCPromptView

SCPromptView : 显示在顶部的提示控件
Swift版
你的star是我最大的动力

已适配iPhoneX

HD.gif

安装

手动安装

下载源码,将SCPromptView文件夹拖进项目

CocoaPod

pod 'SCPromptView'

使用

SCPromptView 的用法,与tableView相似

创建view

#import "SCPromptView.h"

@interface TestPromptView : SCPromptView

@end
#import "TestPromptView.h"

@interface TestPromptView()
/**
 *   label
 */
@property (nonatomic,strong)UILabel *textLabel;
@end

@implementation TestPromptView
//初始化子控件
-(void)sc_setUpCustomSubViews{
    self.backgroundColor=  [UIColor colorWithRed:(arc4random()%255)/255.f green:(arc4random()%255)/255.f blue:(arc4random()%255)/255.f alpha:1];
    UILabel *textLabel = [[UILabel alloc]initWithFrame:self.contentView.bounds];
    textLabel.textColor = [UIColor whiteColor];
    textLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:textLabel];
    self.textLabel = textLabel;
}
//读取参数
-(void)sc_loadParam:(id)param{
    NSString *text = param;
    self.textLabel.text = text;
}
@end

重写两个基础方法

注册

SCPROMPT_REGISTER([TestPromptView class],@"test")
SCPROMPT_REGISTER([ResultPromptView class], @"result")

发送显示命令

///随机颜色显示
-(void)clickBtn:(id)sender{
    NSString * text =[NSString stringWithFormat:@"%d",_num];
    SCPROMPT_SHOW(@"test",text)
    _num++;
}

其他Api

@protocol SCPromptViewDelegate <NSObject>
@required
/**
 *  @brief 添加自定义的子控件
 */
-(void)sc_setUpCustomSubViews;
/**
 *  @brief 子控件读取数据
 */
-(void)sc_loadParam:(id)param;

@optional
/**
 *  @brief 显示时间
 */
-(NSTimeInterval)sc_showTime;
/**
 *  @brief 出现动画时间
 */
-(NSTimeInterval)sc_showAnimationDuration;
/**
 *  @brief 隐藏动画时间
 */
-(NSTimeInterval)sc_hideAnimationDuration;
/**
 *  @brief 即将执行由手势触发的隐藏
 *  @return yes 隐藏 / no 不隐藏
 */
-(BOOL)sc_willHideByTap;

@end

SCPromptView

SCPromptView : A prompt view which show in the top of the screen .

your star is my biggest motivation

HD.gif

Install

Manually

Download the source code , copy folder SCPromptView into your project.

CocoaPod

pod 'SCPromptView'

Usage

The usage of SCPromptView is similar to the usage of UITableView.

Create Custom View

#import "SCPromptView.h"

@interface TestPromptView : SCPromptView

@end
#import "TestPromptView.h"

@interface TestPromptView()
/**
 *   label
 */
@property (nonatomic,strong)UILabel *textLabel;
@end

@implementation TestPromptView
//setUp subviews
-(void)sc_setUpCustomSubViews{
    self.backgroundColor=  [UIColor colorWithRed:(arc4random()%255)/255.f green:(arc4random()%255)/255.f blue:(arc4random()%255)/255.f alpha:1];
    UILabel *textLabel = [[UILabel alloc]initWithFrame:self.contentView.bounds];
    textLabel.textColor = [UIColor whiteColor];
    textLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:textLabel];
    self.textLabel = textLabel;
}
//loadParam which you deliver via command
-(void)sc_loadParam:(id)param{
    NSString *text = param;
    self.textLabel.text = text;
}
@end

Override two basic function.

Register

SCPROMPT_REGISTER([TestPromptView class],@"test")
SCPROMPT_REGISTER([ResultPromptView class], @"result")

发送显示命令

///show random color
-(void)clickBtn:(id)sender{
    NSString * text =[NSString stringWithFormat:@"%d",_num];
    SCPROMPT_SHOW(@"test",text)
    _num++;
}

Other Api

@protocol SCPromptViewDelegate <NSObject>
@required
/**
 *  @brief 添加自定义的子控件
 */
-(void)sc_setUpCustomSubViews;
/**
 *  @brief 子控件读取数据
 */
-(void)sc_loadParam:(id)param;

@optional
/**
 *  @brief 显示时间
 */
-(NSTimeInterval)sc_showTime;
/**
 *  @brief 出现动画时间
 */
-(NSTimeInterval)sc_showAnimationDuration;
/**
 *  @brief 隐藏动画时间
 */
-(NSTimeInterval)sc_hideAnimationDuration;
/**
 *  @brief 即将执行由手势触发的隐藏
 *  @return yes 隐藏 / no 不隐藏
 */
-(BOOL)sc_willHideByTap;

@end
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • PLEASE READ THE FOLLOWING APPLE DEVELOPER PROGRAM LICENSE...
    念念不忘的阅读 13,562评论 5 6
  • afinalAfinal是一个android的ioc,orm框架 https://github.com/yangf...
    passiontim阅读 15,585评论 2 45
  • 岁月不饶人,我亦未曾饶过岁月。——木心 穿梭时光的隧道,凝聚光阴的镌刻,老茶是大自然给与的岁月陈酿。 陈年老茶,是...
    拾点向往阅读 1,562评论 3 50
  • 感谢上天 对我的眷顾, 遇见你, 是我一生最美丽的场景! 与你一起相伴走过的每一段光阴, 在心底深处熠熠生辉 细数...
    锋爷阅读 221评论 0 2
  • 第二十九章 幻觉幻听 话分两头,我们先来说说,早晨六点三十八开始,发生在沈括和刘婷身上的事. 此时,天已经放亮.中...
    笑君杀手阅读 355评论 0 0