ACActionSheet (仿微信ActionSheet效果)

作者: 园丁云 | 来源:发表于2016-05-09 11:38 被阅读2160次

ACActionSheet - 仿微信ActionSheet

系统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
如有问题或建议请联系我,我会马上解决问题~ (ง •̀_•́)ง**

  • 这是微信效果截图
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 delegate               delegate
 *  @param cancelButtonTitle      "取消"按钮         (默认有)
 *  @param destructiveButtonTitle "警示性"(红字)按钮  (可以为空)
 *  @param otherButtonTitles      otherButtonTitles
 */
- (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];

相关文章

网友评论

  • 飞翔的泥巴:为啥看不到内容
    园丁云:貌似简书出bug了。移步一下gayhub
    https://github.com/GardenerYun/ACActionSheet
  • xworld:挺好看的,为什么不加到pod上去呢
    园丁云:@xworld 因为那时候觉得只是个小控件。。近期我就加!
  • 4d370a9022fa:.m 文件里面的- (void)_didClickButton:(UIButton *)button 中respondtoselector里的方法名字好像写错了,要改成actionSheet:didClickedButtonAtIndex:,不然不走代理方法
    园丁云:@davil_233 感谢指出问题!粗心写错了! github 已修改,谢谢支持 !(ง •̀_•́)ง

本文标题:ACActionSheet (仿微信ActionSheet效果)

本文链接:https://www.haomeiwen.com/subject/yfherttx.html