iOS封装弹框(用枚举区别弹框类型)

公司最近要求项目中的弹框格式整理成统一的,因此简单封装了一下。简要代码如下。这里主要记录的是枚举的用法。

基类(父类)的.h文件

typedef NS_ENUM(NSInteger,zb_showWindowType) {
    zb_showWindowType_OneOption,// 一个选择按钮,例如"我知道了"
    zb_showWindowType_TwoOption,// 两个选择按钮,例如"确定","取消"
};


/** 只有一个选项时,rightBtnContent为空字符串即可。其他参数务必有值。*/
/**细节   windowType:(zb_showWindowType)showWindowType相当于定义了枚举属性,只不过写在了方函数中而已。相当于写了@property (nonatomic, assign) zb_showWindowType showWindowType;这句代码,就好理解了*/

-(void)windowType:(zb_showWindowType)showWindowType LeftBtnContent:(NSString *)LeftContent rightBtnContent:(NSString *)rightContent middleContent:(NSString *)middleContent WithCloseWindow:(BOOL)closeWindow;
/** 隐藏遮罩*/
-(void)hiddenBG_BlackView;

基类(父类)的.m文件


-(void)windowType:(zb_showWindowType)showWindowType LeftBtnContent:(NSString *)LeftContent rightBtnContent:(NSString *)rightContent middleContent:(NSString *)middleContent WithCloseWindow:(BOOL)closeWindow{
    
    ..........其余代码..........

    // 选择按钮1个、2个
    switch (showWindowType) {
        case zb_showWindowType_OneOption:// 0
            NSLog(@"一个选择按钮");
            [self createOneSelectBtnWithName:LeftContent];
            break;
        case zb_showWindowType_TwoOption:
            NSLog(@"两个选择按钮");// 1
            [self createTwoSelectBtnWithLeftName:LeftContent RightName:rightContent];
            break;
        default:
            break;
    }    

    .........其余代码..........


}

子类使用时


        [self windowType:zb_showWindowType_TwoOption LeftBtnContent:@"确定" rightBtnContent:@"取消" middleContent:@"确定删除收藏夹吗?\n确定后该收藏夹内所有订单将全部取消收藏" WithCloseWindow:NO];
        
        @weakify(self);
        self.leftAndRightBtn = ^(NSInteger btnTag) {
            @strongify(self);
            if (btnTag == 2018) {
                    NSLog(@"左侧");
                    [self hiddenBG_BlackView];
                 
                     .....其余代码.....
                
            }else if(btnTag == 2019){
                 NSLog(@"右侧");
                 [self hiddenBG_BlackView];
                    .....其余代码.....
            }
        };

你可能感兴趣的:(iOS封装弹框(用枚举区别弹框类型))