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

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

MXAlertView is an easy popView to use !

效果截图

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

如何使用

基本用法

- (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;
}


复制代码

转载于:https://juejin.im/post/5c19f8a26fb9a049bc4c9a01

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值