ACActionSheet - 一個簡潔好用的ActionSheet/AlertView
系統(tǒng)UIActionSheet其實挺好用的定踱。但是有時候系統(tǒng)的風(fēng)格跟APP有些不搭腺占。
而且在iOS8.0 UIKit更新了UIAlertController列牺,蘋果建議:UIActionSheet is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleActionSheet instead。(使用UIActionSheet Xcode就會報deprecate的警告绍昂,挺煩的)
ACActionSheet是仿微信效果的苔埋,簡潔清新奠支,方便好用
GitHub: https://github.com/GardenerYun
Email: gardeneryun@foxmail.com
簡書博客地址: http://www.reibang.com/users/8489e70e237d/latest_articles
如有問題或建議請聯(lián)系我晕讲,我會馬上解決問題~ (? ??_??)?**
2022年01月04日 更新 (v1.0.6)
重寫ACActionSheet
工具拳缠。
1墩新、使用UIScrollView,支持多按鈕脊凰,可滑動抖棘。
2、重寫show動畫狸涌,更絲滑切省。
2019年12月11日 更新 (v1.0.5)
1.優(yōu)化邏輯,并支持CocoaPods: pod 'ACActionSheet'
2.新增類目UIAlertController+ACAlertView
為UIAlertController以UIAlertView(Deprecate)代碼風(fēng)格新增block初始化方法帕胆,詳情見代碼:
+ (instancetype)alertControllerWithTitle:(nullable NSString *)title
message:(nullable NSString *)message
cancelButtonTitle:(nullable NSString *)cancelButtonTitle
confirmButtonTitle:(nullable NSString *)confirmButtonTitle
preferredStyle:(UIAlertControllerStyle)preferredStyle
alertViewBlock:(nullable ACAlertViewBlock)alertViewBlock;
+ (instancetype)alertControllerWithTitle:(nullable NSString *)title
message:(nullable NSString *)message
cancelButtonTitle:(nullable NSString *)cancelButtonTitle
confirmButtonTitle:(nullable NSString *)confirmButtonTitle
otherButtonTitles:(nullable NSArray <NSString *>*)otherButtonTitles
preferredStyle:(UIAlertControllerStyle)preferredStyle
alertViewBlock:(nullable ACAlertViewBlock)alertViewBlock;
(v1.0.0)
- 這是微信效果截圖
- 系統(tǒng)UIActionSheet (UIAlertController)gif 效果圖
代碼示例
ACActionSheet盡力按照蘋果UIKit代碼風(fēng)格編寫朝捆。initWith...創(chuàng)建 -> show方法 -> delegate或block監(jiān)聽事件
- delegate模式 創(chuàng)建
/**
* type delegate
*
* @param title title (可以為空)
* @param delegate delegate
* @param cancelButtonTitle "取消"按鈕 (默認(rèn)有)
* @param destructiveButtonTitle "警示性"(紅字)按鈕 (可以為空)
* @param otherButtonTitles otherButtonTitles
*/
- (instancetype)initWithTitle:(NSString *)title
delegate:(id<ACActionSheetDelegate>)delegate
cancelButtonTitle:(NSString *)cancelButtonTitle
destructiveButtonTitle:(NSString *)destructiveButtonTitle
otherButtonTitles:(NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION;
/***********************************************************************************/
ACActionSheet *actionSheet = [[ACActionSheet alloc] initWithTitle:@"保存或刪除數(shù)據(jù)" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"刪除" otherButtonTitles:@"保存",@"更改", nil];
[actionSheet show];
#pragma mark - ACActionSheet delegate
- (void)actionSheet:(ACActionSheet *)actionSheet didClickedButtonAtIndex:(NSInteger)buttonIndex {
NSLog(@"ACActionSheet delegate - %ld",buttonIndex);
}
- block模式 創(chuàng)建
typedef void(^ACActionSheetBlock)(NSInteger buttonIndex);
/**
* type block
*
* @param title title (可以為空)
* @param cancelButtonTitle "取消"按鈕 (默認(rèn)有)
* @param destructiveButtonTitle "警示性"(紅字)按鈕 (可以為空)
* @param otherButtonTitles otherButtonTitles
* @param actionSheetBlock actionSheetBlock
*/
- (instancetype)initWithTitle:(NSString *)title
cancelButtonTitle:(NSString *)cancelButtonTitle
destructiveButtonTitle:(NSString *)destructiveButtonTitle
otherButtonTitles:(NSArray *)otherButtonTitles
actionSheetBlock:(ACActionSheetBlock) actionSheetBlock;
/***********************************************************************************/
ACActionSheet *actionSheet = [[ACActionSheet alloc] initWithTitle:nil cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@[@"小視頻",@"拍照",@"從手機(jī)相冊選擇"] actionSheetBlock:^(NSInteger buttonIndex) {
NSLog(@"ACActionSheet block - %ld",buttonIndex);
}];
[actionSheet show];