AFMActionSheet 2.0.0

AFMActionSheet 2.0.0

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2016年10月
SPM支持 SPM

Ilya Alesker 维护。




AFMActionSheet

AFMActionSheet 提供了一个 AFMActionSheetController,可以在需要自定义外观或自定义显示/消失动画的地方使用,类似于在 UIAlertController 中使用的位置。鉴于 AFMActionSheetController 是受到 UIAlertController 启发的,它也支持 ActionSheet 和 Alert 风格,以使您的生活更加方便。

Action Sheet Example Alert Example

用法

创建一个带有默认样式和默认过渡动画的操作表

let actionSheet = AFMActionSheetController()
let action = AFMAction(title: "Action", enabled: true, handler: { (action: AFMAction) -> Void in
    // Do something in handler
}
actionSheet.add(action)
self.present(actionSheet, animated: true, completion: {
    // Do something after completion
})

就这样。

详细查看

样式

AFMActionSheetController 支持两种样式:默认操作表样式和警报样式。这些样式通过具有 ControllertStyle 枚举的初始化器设置(相应地是 ControllertStyle.actionSheetControllertStyle.alert

let actionSheet = AFMActionSheetController(style: .actionSheet)
let alert = AFMActionSheetController(style: .alert)

过渡动画

要更改显示和消失动画,实现 UIViewControllerTransitioningDelegate 并将其传递给 AFMActionSheetController

let actionSheet = AFMActionSheetController(transitioningDelegate: myCustomTransitioningDelegate)

或者

actionSheet.setup(myCustomTransitioningDelegate)

操作控件

操作表的控件是通过将 AFMAction 对象添加到控制器中创建的

actionSheet.add(action)

还可以将这些操作作为“取消操作”添加。当使用 ControllertStyle.ActionSheet 样式时,这些操作的控件将显示在底部的“取消部分”中。

actionSheet.add(cancelling: action)

要使用自定义视图作为操作控件,只需将具有操作的自定义视图传递到 add(_:with:)add(cancelling:with:) 方法。

actionSheet.add(action, with: myCustomControl)
actionSheet.add(cancelling: action, with: myCustomControl)

操作控件的高度由自定义视图指定的任何高度,但可以通过 minControlHeight 属性指定最小控件高度。

标题视图

标题视图是位于操作表顶部的视图,其功能类似于操作控件。要使用自定义视图设置标题视图

actionSheet.add(title: myCustomTitleView)

或将默认的 UILabel 设置为文本

actionSheet.add(titleLabelWith: "Title")

如操作控件高度一样,可以使用 minTitleHeight 属性指定最小控件高度。

其他自定义

有一些属性可以帮助进一步修改动作表控制器的外观和行为

  • spacing: Int 用来指定动作控制按钮之间的间距(默认为 4
  • horizontalMargin: Int 用来指定内容到控制器顶部和底部的间距(默认为 16
  • verticalMargin: Int 用来指定内容到控制器左右两侧的间距(默认为 16
  • cornerRadius: Int 用来指定内容的圆角半径(默认为 10
  • backgroundColor: UIColor 用来指定控制器的背景颜色(默认为 blackColor().colorWithAlphaComponent(0.5)
  • spacingColor: UIColor 用来指定内容的间距颜色(默认为 .clearColor()
  • outsideGestureShouldDismiss: Bool 来指定在控制按钮和标题外部点击背景是否关闭动作表单(默认为 true

示例项目

要运行示例项目,首先克隆仓库,然后从示例目录运行 pod install

要求

iOS 8 及以上版本。

安装

AFMActionSheet 通过 CocoaPods 提供。要安装它,只需在您的 Podfile 中添加以下行

pod "AFMActionSheet"

联系人

Ilya Alesker,[email protected]

许可

AFMActionSheet 在 MIT 许可下提供。查看 LICENSE 文件获取更多信息。