一、效果展示
GitHub更多效果展示圖片
二、安裝
注:為了支持CocoaPods安裝,但是MSAlertController
已被人搶占,不得已只能將CocoaPods庫中的名字改為MSAlertVC
,因此在安裝完MSAlertVC
后,引入頭文件應(yīng)該為MSAlertController.h
,而非MSAlertVC.h
1.CocoaPods
- 在 Podfile 中添加
pod 'MSAlertVC'
; - 執(zhí)行
pod install
或pod update
; - 導(dǎo)入頭文件:
#import <MSAlertController.h>
。
2.手動(dòng)安裝
- 下載
MSAlertVC
項(xiàng)目; - 將
MSAlertController
文件夾直接拖入項(xiàng)目中; - 導(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];