ACActionSheet - 一個簡潔好用的ActionSheet/AlertView
系統UIActionSheet其實挺好用的。但是有時候系統的風格跟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.lxweimin.com/users/8489e70e237d/latest_articles
如有問題或建議請聯系我,我會馬上解決問題~ (? ??_??)?**
2022年01月04日 更新 (v1.0.6)
重寫ACActionSheet
工具。
1、使用UIScrollView,支持多按鈕,可滑動。
2、重寫show動畫,更絲滑。
2019年12月11日 更新 (v1.0.5)
1.優化邏輯,并支持CocoaPods: pod 'ACActionSheet'
2.新增類目UIAlertController+ACAlertView
為UIAlertController以UIAlertView(Deprecate)代碼風格新增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)
- 這是微信效果截圖
ACAcitonSheet_03
ACAcitonSheet_01
ACAcitonSheet_02
- 系統UIActionSheet (UIAlertController)gif 效果圖
系統ActionSheet.gif
ACActionSheet.gif
代碼示例
ACActionSheet盡力按照蘋果UIKit代碼風格編寫。initWith...創建 -> show方法 -> delegate或block監聽事件
- delegate模式 創建
/**
* type delegate
*
* @param title title (可以為空)
* @param delegate delegate
* @param cancelButtonTitle "取消"按鈕 (默認有)
* @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:@"保存或刪除數據" 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模式 創建
typedef void(^ACActionSheetBlock)(NSInteger buttonIndex);
/**
* type block
*
* @param title title (可以為空)
* @param cancelButtonTitle "取消"按鈕 (默認有)
* @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:@[@"小視頻",@"拍照",@"從手機相冊選擇"] actionSheetBlock:^(NSInteger buttonIndex) {
NSLog(@"ACActionSheet block - %ld",buttonIndex);
}];
[actionSheet show];