iOS 自定义Actionsheet

自定义的Actionsheet效果如下

自定义的思路

1.在window上添加两个图层,背景层和功能层,如下图

2.设置背景层的背景色和透明度,并在背景层上添加点击事件

3.将自定义的view添加为功能层的subView,功能层的frame根据自定义view来变化

注意:背景层和功能层是在同一层面,是重叠的关系,而不是子父视图的关系,因此添加这两个view的时候要注意先后顺序,以此确定哪层在上

我封装了一下

用的时候把下面两个文件导入

#import "CZQActionSheet.h"//导入
UIView *view = [[UIView alloc] init];//创建自定义view
CZQActionSheet *actionSheet = [CZQActionSheet shardCZQActionSheetWithContainedView:view];//创建actionsheet并将自定义view传进去
[actionSheet show];//显示actionSheet
[actionSheet close];//关闭actionSheet

示例:https://github.com/TigerCui/CZQActionSheet.git

posted @ 2016-02-14 15:05  TigerCui  阅读(955)  评论(0编辑  收藏  举报