取代你的Toast-->SCPromptView

SCPromptView

SCPromptView : 顯示在頂部的提示控件
Swift版
你的star是我最大的動力

已適配iPhoneX

HD.gif

安裝

手動安裝

下載源碼,將SCPromptView文件夾拖進項目

CocoaPod

pod 'SCPromptView'

使用

SCPromptView 的用法,與tableView相似

創(chuàng)建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;
}
//讀取參數(shù)
-(void)sc_loadParam:(id)param{
    NSString *text = param;
    self.textLabel.text = text;
}
@end

重寫兩個基礎方法

注冊

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

發(fā)送顯示命令

///隨機顏色顯示
-(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 子控件讀取數(shù)據(jù)
 */
-(void)sc_loadParam:(id)param;

@optional
/**
 *  @brief 顯示時間
 */
-(NSTimeInterval)sc_showTime;
/**
 *  @brief 出現(xiàn)動畫時間
 */
-(NSTimeInterval)sc_showAnimationDuration;
/**
 *  @brief 隱藏動畫時間
 */
-(NSTimeInterval)sc_hideAnimationDuration;
/**
 *  @brief 即將執(zhí)行由手勢觸發(fā)的隱藏
 *  @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")

發(fā)送顯示命令

///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 子控件讀取數(shù)據(jù)
 */
-(void)sc_loadParam:(id)param;

@optional
/**
 *  @brief 顯示時間
 */
-(NSTimeInterval)sc_showTime;
/**
 *  @brief 出現(xiàn)動畫時間
 */
-(NSTimeInterval)sc_showAnimationDuration;
/**
 *  @brief 隱藏動畫時間
 */
-(NSTimeInterval)sc_hideAnimationDuration;
/**
 *  @brief 即將執(zhí)行由手勢觸發(fā)的隱藏
 *  @return yes 隱藏 / no 不隱藏
 */
-(BOOL)sc_willHideByTap;

@end
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

  • PLEASE READ THE FOLLOWING APPLE DEVELOPER PROGRAM LICENSE...
    念念不忘的閱讀 13,640評論 5 6
  • afinalAfinal是一個android的ioc,orm框架 https://github.com/yangf...
    passiontim閱讀 15,835評論 2 45
  • 歲月不饒人,我亦未曾饒過歲月?!拘?穿梭時光的隧道,凝聚光陰的鐫刻,老茶是大自然給與的歲月陳釀。 陳年老茶,是...
    拾點向往閱讀 1,629評論 3 50
  • 感謝上天 對我的眷顧, 遇見你, 是我一生最美麗的場景! 與你一起相伴走過的每一段光陰, 在心底深處熠熠生輝 細數(shù)...
    鋒爺閱讀 230評論 0 2
  • 第二十九章 幻覺幻聽 話分兩頭,我們先來說說,早晨六點三十八開始,發(fā)生在沈括和劉婷身上的事. 此時,天已經放亮.中...
    笑君殺手閱讀 374評論 0 0

友情鏈接更多精彩內容