MSAlertController——一个高仿微博和微信的底部弹窗控制器

Github源码地址

一、效果展示


GitHub更多效果展示图片

二、安装

注:为了支持CocoaPods安装,但是MSAlertController已被人抢占,不得已只能将CocoaPods库中的名字改为MSAlertVC,因此在安装完MSAlertVC后,引入头文件应该为MSAlertController.h,而非MSAlertVC.h

1.CocoaPods

  1. 在 Podfile 中添加 pod 'MSAlertVC'
  2. 执行 pod installpod update
  3. 导入头文件:#import <MSAlertController.h>

2.手动安装

  1. 下载 MSAlertVC 项目;
  2. MSAlertController 文件夹直接拖入项目中;
  3. 导入头文件:#import "MSAlertController.h"

三、使用方法

1.初始化MSAlertController

+ (_Nonnull instancetype)alertControllerWithArray:(nonnull NSArray <NSString *> *)confirmArray;

2.自定义属性

title
rowHeight

3.自定义方法

// 设置第index行的按钮的颜色(可选实现的方法)
- (void)setColor:(nonnull UIColor *)color withIndex:(NSInteger)index;
// 设置第index行的按钮的字体(可选实现的方法)
- (void)setFont:(nonnull UIFont *)font withIndex:(NSInteger)index;
// 设置取消按钮的文字内容和颜色字体(可选实现的方法)
- (void)setCancleButtonTitle:(nonnull NSString *)title font:(nonnull UIFont *)font color:(nonnull UIColor *)color;

4.点击事件

- (void)addConfirmButtonAction:(nullable MSButtonBlock)block;

四、使用示例

示例1

NSArray *arr = @[@"保存图片", @"转发微博", @"赞"];
MSAlertController *alertVC = [MSAlertController alertControllerWithArray:arr];
[alertVC addConfirmButtonAction:^(NSInteger index, BOOL cancle) {
    if (cancle) {
        NSLog(@"你点击了取消按钮");
        return;
    } 
    NSLog(@"你点击的是:%@", arr[index]);
}];
[self presentViewController:alertVC animated:NO completion:nil];

示例2

MSAlertController *unfollowAlertVC = [MSAlertController alertControllerWithArray:@[@"不再关注"]];
unfollowAlertVC.title = @"你确定不再关注MS了吗?";
[unfollowAlertVC setColor:[UIColor redColor] withIndex:0];
[unfollowAlertVC addConfirmButtonAction:^(NSInteger index, BOOL cancle) {
    if (cancle) {
        NSLog(@"你点击了取消按钮");
        return;
    }
    NSLog(@"果取关");
}];
[self presentViewController:unfollowAlertVC animated:NO completion:nil];

Github源码地址

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

推荐阅读更多精彩内容

  • Swift版本点击这里欢迎加入QQ群交流: 594119878最新更新日期:18-09-17 About A cu...
    ylgwhyh阅读 25,684评论 7 249
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 14,238评论 4 61
  • 他初到金陵城下,一身青衣素麻,端坐在马车之中,透过半掩的遮帘,久久的临望着城楼上刻着的“金陵”二字。是啊,对于他来...
    961347703083阅读 5,691评论 31 33
  • 我双脚骤停 成千里外的路人 千里外路边的人 上车 下车 路呼啸而过 红绿灯没有错 斑马跳出来 制造一场车祸 花纹排...
    lh就是我阅读 1,189评论 0 4
  • 有时候不是你不够努力,不够优秀,而是缘分太浅,你把对方当做神供奉着,对方把你当做风一样的过客。 最近煲剧《漂亮的李...
    粥渔阅读 4,496评论 3 2