MSAlertController——一個(gè)高仿微博和微信的底部彈窗控制器

Github源碼地址

一、效果展示


GitHub更多效果展示圖片

二、安裝

注:為了支持CocoaPods安裝,但是MSAlertController已被人搶占,不得已只能將CocoaPods庫中的名字改為MSAlertVC,因此在安裝完MSAlertVC后,引入頭文件應(yīng)該為MSAlertController.h,而非MSAlertVC.h

1.CocoaPods

  1. 在 Podfile 中添加 pod 'MSAlertVC'
  2. 執(zhí)行 pod installpod update
  3. 導(dǎo)入頭文件:#import <MSAlertController.h>

2.手動(dòng)安裝

  1. 下載 MSAlertVC 項(xiàng)目;
  2. MSAlertController 文件夾直接拖入項(xiàng)目中;
  3. 導(dǎo)入頭文件:#import "MSAlertController.h"

三、使用方法

1.初始化MSAlertController

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

2.自定義屬性

title
rowHeight

3.自定義方法

// 設(shè)置第index行的按鈕的顏色(可選實(shí)現(xiàn)的方法)
- (void)setColor:(nonnull UIColor *)color withIndex:(NSInteger)index;
// 設(shè)置第index行的按鈕的字體(可選實(shí)現(xiàn)的方法)
- (void)setFont:(nonnull UIFont *)font withIndex:(NSInteger)index;
// 設(shè)置取消按鈕的文字內(nèi)容和顏色字體(可選實(shí)現(xiàn)的方法)
- (void)setCancleButtonTitle:(nonnull NSString *)title font:(nonnull UIFont *)font color:(nonnull UIColor *)color;

4.點(diǎn)擊事件

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

四、使用示例

示例1

NSArray *arr = @[@"保存圖片", @"轉(zhuǎn)發(fā)微博", @"贊"];
MSAlertController *alertVC = [MSAlertController alertControllerWithArray:arr];
[alertVC addConfirmButtonAction:^(NSInteger index, BOOL cancle) {
    if (cancle) {
        NSLog(@"你點(diǎn)擊了取消按鈕");
        return;
    } 
    NSLog(@"你點(diǎn)擊的是:%@", arr[index]);
}];
[self presentViewController:alertVC animated:NO completion:nil];

示例2

MSAlertController *unfollowAlertVC = [MSAlertController alertControllerWithArray:@[@"不再關(guān)注"]];
unfollowAlertVC.title = @"你確定不再關(guān)注MS了嗎?";
[unfollowAlertVC setColor:[UIColor redColor] withIndex:0];
[unfollowAlertVC addConfirmButtonAction:^(NSInteger index, BOOL cancle) {
    if (cancle) {
        NSLog(@"你點(diǎn)擊了取消按鈕");
        return;
    }
    NSLog(@"果取關(guān)");
}];
[self presentViewController:unfollowAlertVC animated:NO completion:nil];

Github源碼地址

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • Swift版本點(diǎn)擊這里歡迎加入QQ群交流: 594119878最新更新日期:18-09-17 About A cu...
    ylgwhyh閱讀 25,579評論 7 249
  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫、插件、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 12,259評論 4 61
  • 他初到金陵城下,一身青衣素麻,端坐在馬車之中,透過半掩的遮簾,久久的臨望著城樓上刻著的“金陵”二字。是啊,對于他來...
    961347703083閱讀 1,746評論 31 33
  • 我雙腳驟停 成千里外的路人 千里外路邊的人 上車 下車 路呼嘯而過 紅綠燈沒有錯(cuò) 斑馬跳出來 制造一場車禍 花紋排...
    lh就是我閱讀 179評論 0 4
  • 有時(shí)候不是你不夠努力,不夠優(yōu)秀,而是緣分太淺,你把對方當(dāng)做神供奉著,對方把你當(dāng)做風(fēng)一樣的過客。 最近煲劇《漂亮的李...
    粥漁閱讀 901評論 3 2