美文网首页
MXAlertView,一行代码实现iOS带动画的弹出视图

MXAlertView,一行代码实现iOS带动画的弹出视图

作者: 穿山甲到底说了什么 | 来源:发表于2018-01-21 16:56 被阅读0次

    代码demo已在Github开源, MXAlertView, 如果能帮助到您,请帮忙点个星star哈,谢谢!

    MXAlertView is an easy popView to use !

    效果截图

    选择按钮一个 选择按钮两个 选择按钮三个 自定义accessoryView
    选择按钮一个.gif 选择按钮两个.gif 选择按钮三个.gif 自定义accessoryView.gif

    如何使用

    基本用法

    - (IBAction)alertTypeOneClicked {
        
        [MXAlertView showWithTopTitle:@"提示" bottomTitles:@[@"关闭播放"] content:@"你当前在4G模式,确定要播放?" dataSource:nil completionHandler:nil];
    }
    
    - (IBAction)alertTypeTwoClicked {
        
        [MXAlertView showWithTopTitle:@"提示" bottomTitles:@[@"关闭播放", @"前去设置"] content:@"你当前在4G模式,确定要播放?" dataSource:nil completionHandler:nil];
    }
    
    - (IBAction)alertTypeThreeClicked {
    
        [MXAlertView showWithTopTitle:@"提示" bottomTitles:@[@"关闭播放", @"继续播放", @"前去设置"] content:@"你当前在4G模式,确定要播放?" dataSource:nil completionHandler:^(int index, UIButton *sender) {
            
            //selected index is index in the `bottomTitles`
            if (index == 0) {
                //关闭播放
            } else if (index == 1) {
                //继续播放
            } else {
                //前去设置
            }
        }];
    }
    
    

    自定义

    设置 dataSource 之后在代理中实现MXAlertViewDataSource 中的accessoryViewForContentInMXAlertView

    - (IBAction)alertTypeFourClicked {
        
        [MXAlertView showWithTopTitle:@"提示" bottomTitles:@[@"关闭播放", @"前去设置"] content:@"你当前在4G模式,确定要播放?" dataSource:self completionHandler:^(int index, UIButton *sender) {
            
            //selected index is the same index as title in the `bottomTitles`
            if (index == 0) {
                //关闭播放
            } else if (index == 1) {
                //继续播放
            } else {
                //前去设置
            }
        }];
    }
    
    - (UIView *)accessoryViewForContentInMXAlertView:(MXAlertView *)alertView {
        
        UIView *accessoryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width - 4 * 15, 20)];
        
        UIView *timerImageView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
        timerImageView.layer.contents = (__bridge id)[[UIImage imageNamed:@"时钟.png"] CGImage];
        [accessoryView addSubview:timerImageView];
        
        CGRect timerImageViewFrame = timerImageView.frame;
        UILabel *timerLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(timerImageViewFrame) + 2, timerImageViewFrame.origin.y, 50, CGRectGetHeight(timerImageViewFrame))];
        timerLabel.font = [UIFont systemFontOfSize:15];
        timerLabel.textColor = [UIColor colorWithRed:49/255.0 green:194/255.0 blue:124/255.0 alpha:1.0];
        timerLabel.text = @"2:00";
        [accessoryView addSubview:timerLabel];
        
        return accessoryView;
    }
    
    
    

    相关文章

      网友评论

          本文标题:MXAlertView,一行代码实现iOS带动画的弹出视图

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