先上效果圖
再上demo地址 如果覺(jué)得好用請(qǐng)給star鼓勵(lì) 謝謝
github demo
項(xiàng)目介紹
- 這是一款簡(jiǎn)約系統(tǒng)風(fēng)格的彈窗抬虽,開(kāi)發(fā)者可通過(guò)一句代碼創(chuàng)建并彈出官觅。
- 開(kāi)發(fā)者可以選擇通過(guò)代理的方式或者block的方式來(lái)監(jiān)聽(tīng)按鈕的點(diǎn)擊事件。
- 開(kāi)發(fā)者可通過(guò)settingHandler設(shè)置彈窗的背景顏色阐污、字體顏色休涤、字體以及分割線(xiàn)的顏色以滿(mǎn)足不同風(fēng)格的app的需求
- 更加詳盡的使用情況請(qǐng)下載demo
使用說(shuō)明
安裝
將demo中的SLAlertView文件夾拖入項(xiàng)目
接口說(shuō)明
/**
* 創(chuàng)建并彈出使用代理監(jiān)聽(tīng)點(diǎn)擊事件的默認(rèn)的alertView
* param title 標(biāo)題
* param message 提示文字內(nèi)容
* param delegate 代理 可通過(guò)設(shè)置代理監(jiān)聽(tīng)按鈕的點(diǎn)擊
* param preferredStyle 彈出樣式
* param cancelButtonTitle 取消按鈕文字
* param otherButtonTitles 其他按鈕文字(數(shù)組)@[@"other1",@"other2"]
*/
+ (void)alertViewWithTitle:(nullable NSString *)title
message:(nullable NSString *)message
delegate:(nullable id<SLAlertViewProtocol>)delegate
preferredStyle:(SLAlertViewStyle)preferredStyle
cancelButtonTitle:(nullable NSString *)cancelButtonTitle
otherButtonTitles:(nullable NSArray *)otherButtonTitles;
/**
* 創(chuàng)建并彈出使用block監(jiān)聽(tīng)點(diǎn)擊事件的默認(rèn)的alertView
* param title 標(biāo)題
* param message 提示文字內(nèi)容
* param preferredStyle 彈出樣式
* param cancelButtonTitle 取消按鈕文字
* param otherButtonTitles 其他按鈕文字(數(shù)組)@[@"other1",@"other2"]
* param clickHandler 點(diǎn)擊按鈕的回調(diào)
*/
+ (void)alertViewWithTitle:(nullable NSString *)title
message:(nullable NSString *)message
preferredStyle:(SLAlertViewStyle)preferredStyle
cancelButtonTitle:(nullable NSString *)cancelButtonTitle
otherButtonTitles:(nullable NSArray *)otherButtonTitles
clickHandler:(nullable void (^)(SLAlertView * _Nonnull alertView,NSInteger buttonIndex,NSString * _Nullable buttonTitle))clickHandler;
/**
* 創(chuàng)建并彈出使用代理監(jiān)聽(tīng)點(diǎn)擊事件的可自定義的alertView
* param title 標(biāo)題
* param message 提示文字內(nèi)容
* param delegate 代理 可通過(guò)設(shè)置代理監(jiān)聽(tīng)按鈕的點(diǎn)擊
* param preferredStyle 彈出樣式
* param cancelButtonTitle 取消按鈕文字
* param otherButtonTitles 其他按鈕文字(數(shù)組)@[@"other1",@"other2"]
* param settingHandler 自定義設(shè)置的回調(diào) 可通過(guò)此block設(shè)置各種背景顏色、字體顏色和字體笛辟。
自定義設(shè)置方式:
alertView.titleColor = [UIColor blackColor];
alertView.messageColor = [UIColor blackColor];
...
*/
+ (void)alertViewWithTitle:(nullable NSString *)title
message:(nullable NSString *)message
delegate:(nullable id<SLAlertViewProtocol>)delegate
preferredStyle:(SLAlertViewStyle)preferredStyle
cancelButtonTitle:(nullable NSString *)cancelButtonTitle
otherButtonTitles:(nullable NSArray *)otherButtonTitles
settingHandler:(nullable void (^)( SLAlertView * _Nonnull alertView))settingHandler;
/**
* 創(chuàng)建并彈出使用block監(jiān)聽(tīng)點(diǎn)擊事件的可自定義的alertView
* param title 標(biāo)題
* param message 提示文字內(nèi)容
* param preferredStyle 彈出樣式
* param cancelButtonTitle 取消按鈕文字
* param otherButtonTitles 其他按鈕文字(數(shù)組)@[@"other1",@"other2"]
* param settingHandler 自定義設(shè)置的回調(diào) 可通過(guò)此block設(shè)置各種背景顏色功氨、字體顏色和字體。
自定義設(shè)置方式:
alertView.titleColor = [UIColor blackColor];
alertView.messageColor = [UIColor blackColor];
...
* param clickHandler 點(diǎn)擊按鈕的回調(diào)
*/
+ (void)alertViewWithTitle:(nullable NSString *)title
message:(nullable NSString *)message
preferredStyle:(SLAlertViewStyle)preferredStyle
cancelButtonTitle:(nullable NSString *)cancelButtonTitle
otherButtonTitles:(nullable NSArray *)otherButtonTitles
settingHandler:(nullable void (^)( SLAlertView * _Nonnull alertView))settingHandler
clickHandler:(nullable void (^)(SLAlertView * _Nonnull alertView,NSInteger buttonIndex,NSString * _Nullable buttonTitle))clickHandler;
// 代理方法
- (void)alertView:(SLAlert * _Nonnull)alertView didSelectedButtonWithButtonIndex:(NSInteger)index buttonTitle:(NSString * _Nullable)buttonTitle;
- (void)actionSheet:(SLActionSheet * _Nonnull)actionSheet didSelectedButtonWithButtonIndex:(NSInteger)index buttonTitle:(NSString * _Nullable)buttonTitle;
調(diào)用
- 導(dǎo)入頭文件
#import "SLAlertView.h"
- 在需要彈窗的地方調(diào)用接口
1> 創(chuàng)建并彈出使用代理監(jiān)聽(tīng)點(diǎn)擊事件的默認(rèn)的alert / actionSheet
// alert
[SLAlertView alertViewWithTitle:@"title"
message:@"messagemessagemessagemessagemessagemessagemessagemessaemessagemessage"
delegate:self
preferredStyle:SLAlertViewStyleAlert
cancelButtonTitle:@"cancel"
otherButtonTitles:nil];
// action sheet
[SLAlertView alertViewWithTitle:@"title"
message:@"this is message"
delegate:self
preferredStyle:SLAlertViewStyleActionSheet
cancelButtonTitle:@"cancel"
otherButtonTitles:@[@"other"]];
2> 創(chuàng)建并彈出使用block監(jiān)聽(tīng)點(diǎn)擊事件的默認(rèn)的alert / actionSheet
// 通過(guò)block回調(diào)方式創(chuàng)建alert
[SLAlertView alertViewWithTitle:@"title"
message:@"message"
preferredStyle:SLAlertViewStyleAlert
cancelButtonTitle:@"cancel"
otherButtonTitles:@[@"other"]
clickHandler:^(SLAlertView * _Nonnull alertView, NSInteger buttonIndex, NSString * _Nullable buttonTitle) {
NSLog(@"block %ld-%@",buttonIndex,buttonTitle);
}];
// 通過(guò)block回調(diào)方式創(chuàng)建action sheet
[SLAlertView alertViewWithTitle:@"actionSheet"
message:@"sheet_default"
preferredStyle:SLAlertViewStyleActionSheet
cancelButtonTitle:@"cancel"
otherButtonTitles:@[@"other1",@"other2",@"other3"]
clickHandler:^(SLAlertView * _Nonnull alertView, NSInteger buttonIndex, NSString * _Nullable buttonTitle) {
NSLog(@"block sheet_default %ld-%@",buttonIndex,buttonTitle);
}];
3> 自定義的情況(以actionSheet為例手幢,alert用法完全一樣)
[SLAlertView alertViewWithTitle:@"title"
message:@"message"
preferredStyle:SLAlertViewStyleActionSheet
cancelButtonTitle:@"cancel"
otherButtonTitles:@[@"other1",@"other2"]
settingHandler:^(SLAlertView * _Nonnull alertView) {
alertView.titleBackgroundColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha:1.0];
alertView.messageBackgroundColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha:1.0];
alertView.otherBackgroundColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha:1.0];
alertView.cancelBackgroundColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha:1.0];
alertView.titleColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha:1.0];
alertView.messageColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha:1.0];
alertView.otherTitleColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha:1.0];
alertView.cancelTitleColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha:1.0];
alertView.separatorColor = [UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha:1.0];
alertView.titleFont = [UIFont fontWithName:@"AmericanTypewriter-Bold" size:16];
alertView.messageFont = [UIFont fontWithName:@"AmericanTypewriter" size:16];
alertView.otherTitleFont = [UIFont fontWithName:@"DBLCDTempBlack" size:16];
alertView.cancelTitleFont = [UIFont fontWithName:@"AmericanTypewriter-Bold" size:16];
}
clickHandler:^(SLAlertView * _Nonnull alertView, NSInteger buttonIndex, NSString * _Nullable buttonTitle) {
NSLog(@"block sheet_customBackgroundColor %ld-%@",buttonIndex,buttonTitle);
}];
4> 代理方法捷凄。遵守協(xié)議 <SLAlertViewProtocol>
- (void)actionSheet:(SLActionSheet *)actionSheet didSelectedButtonWithButtonIndex:(NSInteger)index buttonTitle:(NSString *)buttonTitle {
NSLog(@"actionSheet:didSelectedButtonWithButtonIndex:%ld buttonTitle:%@",index,buttonTitle);
}
- (void)alertView:(SLAlert *)alertView didSelectedButtonWithButtonIndex:(NSInteger)index buttonTitle:(NSString *)buttonTitle {
NSLog(@"alertView:didSelectedButtonWithButtonIndex:%ld buttonTitle:%@",index,buttonTitle);
}
轉(zhuǎn)載請(qǐng)注明出處,好用請(qǐng)github star围来。謝謝跺涤!