封装简便弹出框

作者: 爱偷懒的万万 | 来源:发表于2016-07-30 16:03 被阅读382次

每次写弹出框的时候,UIAlertView的代理写得特别麻烦,而且当代码越多,找起来就比较麻烦,我用block进行了简单封装。以后遇到会重复用到的代码段,都可以像这样进行封装。

直接上代码:

LLAlertView.h
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

    typedef void(^ReturnBlock)();
    @interface LLAlertView : NSObject

    @property (nonatomic,copy)ReturnBlock cancelBlock;
    @property (nonatomic,copy)ReturnBlock tureBlock;

    + (void)creatAlertViewWithTitle:(NSString *)titleText withMessage:(NSString *)messageText withcancelTitle:(NSString *)cancelText withCancelBlock:(ReturnBlock)cancelBlock withotherTitle:(NSString *)otherText  withotherBlock:(ReturnBlock)tureBlock;

    @end

LLAlertView.m
#import "LLAlertView.h"

     static LLAlertView *__alertView;

    @implementation LLAlertView

    + (void)creatAlertViewWithTitle:(NSString *)titleText  withMessage:(NSString *)messageText withcancelTitle:(NSString *)cancelText withCancelBlock:(ReturnBlock)cancelBlock withotherTitle:(NSString *)otherText  withotherBlock:(ReturnBlock)tureBlock{

        if (nil == __alertView) {
            __alertView = [[LLAlertView alloc]init];
        }

        __alertView.cancelBlock = cancelBlock;
        __alertView.tureBlock = tureBlock;
        UIAlertView *alertview = [[UIAlertView alloc]initWithTitle:titleText message:messageText delegate:__alertView cancelButtonTitle:cancelText otherButtonTitles:otherText, nil];
        [alertview show];

    }

    #pragma mark - AlertView Delegte
    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

        switch (buttonIndex) {
            case 0:
                if (_cancelBlock) {
                    _cancelBlock();
                }
        
                break;
            case 1:
                if (_tureBlock) {
                    _tureBlock();
                }
                break;
            default:
                break;
        }

    }

Demo下载请看这里:LLAlertView

希望能帮到大家,虽然只是一个小的例子,希望能活学活用,封装出更多的东西。

相关文章

  • 封装简便弹出框

    每次写弹出框的时候,UIAlertView的代理写得特别麻烦,而且当代码越多,找起来就比较麻烦,我用block进行...

  • XXAlertView使用

    XXAlertView对UIAlertController封装,能够方便的实现警告框。 使用方法 弹出提示框 弹出...

  • 自定义android弹出框

    概述 android上原生的弹出框和ios原生的弹出框视觉差距较大,为了与ios的视觉效果类似,所以封装了这个库。...

  • Android 多种简单的弹出框样式设置

    简介 这是一个基于AlertDialog和Dialog这两个类封装的多种弹出框样式,其中提供各种简单样式的弹出框使...

  • 利用原生js简单封装confirm弹出框

    由于项目需要,做了一个超级简单的弹出框,一打开页面就弹出弹出框。由于项目总监说要尽量小(少引入封装的文件包),所以...

  • 封装弹出框插件

    封装思想 1、先封装一个Alerts类 用来生成弹出框的页面结构 1.1 属性:提示头提示信息字体颜色 1.2 方...

  • react native 简单的弹出框

    模仿原生效果的弹出框封装的组件 style样式 父组件调用

  • 2018-01-09多种简单的弹出框样式设置

    这是一个基于AlertDialog和Dialog这两个类封装的多种弹出框样式,其中提供各种简单样式的弹出框使用说明...

  • CommonListDiaLogs 统一dialog 弹出框

    CommonListDiaLogs 封装通用dialog 弹出框 由于每次写dialog都要写很多重复代码,因此...

  • iVIew对话框封装

    弹出框使用率较高,将其封装为组件 @/components/tip-modal/index.vue: 对比查看 使用:

网友评论

    本文标题:封装简便弹出框

    本文链接:https://www.haomeiwen.com/subject/qcltsttx.html