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

代码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;
}


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1、通过CocoaPods安装项目名称项目信息 AFNetworking网络请求组件 FMDB本地数据库组件 SD...
    阳明AI阅读 16,019评论 3 119
  • 老豹是村里出了名的老实人。村里人都觉得这名字跟了他算是糟践了。 说老豹老实,是因为老豹在村里从没跟人红过脸,不吹牛...
    冯小高阅读 731评论 7 6
  • 周日,去文化街溜达,看见一位残疾人在人来人往的大街上乞讨,而且只有他一个人在这条街上乞讨。他的腿和手变形,...
    流动的温暖阅读 1,670评论 0 1
  • 1. 举例: (1) 肚子饿时,进食能提升舒服程度,人会喜欢上进食。 (2) 肚子饿时,吃鱼能提升舒服程度,人会喜...
    王程远阅读 892评论 0 0
  • 你被托出海面 我的泪水染红了霞光 你终究是属于光明 而我无法离开海洋 伴着你炙热的目光 我每天都要跨过整个海洋 拥...
    心安何所归阅读 614评论 0 20