ACActionSheet (仿微信ActionSheet效果)

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.jianshu.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];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,267评论 4 61
  • 很久没有分享美食给大家啦!其实今天我给大家分享的是特别平常的菜肴,在家中,休闲的时候可以多做一些美味,来熏陶家人们...
    食美者阅读 395评论 0 2
  • 匆匆忙忙地驾车回家,吃个饭,睡一觉,又驾车匆匆忙忙地赶上来工作的城市,家,似乎一下子变得有些陌生,爸妈似乎也变得陌...
    耳朵在聆听阅读 502评论 0 0
  • 运动、挨饿、按摩……关于减肥,很多人试了很多种方法,可是体重就是减不下来或是减下来了很容易反弹回去。 其实,只要把...
    健身客阅读 793评论 0 10
  • K歌五个多小时,好几首新的歌曲第一次唱,居然很不错,哈哈 王菲《闷》 蔡健雅《Beautiful Love》《陌生...
    面包树上的小熊考拉阅读 278评论 0 0