ANActionSheetController
ANActionSheetController是一个高度可定制的UIAlertController副本,看起来像内置的动作表,在iPad上也能工作。
看起来像什么?(9.5 MB gif文件 - 可能需要等待一段时间)
为什么?
ANActionSheetController可以具有许多动作,一个与其它动作区分开的取消动作,以及标题和/或消息,就像内置的UIAlertController一样。但不同之处在于;你可以定制几乎所有的属性。
所需的最基本东西是至少有一个动作。
您可以自定义什么?
通过修改控制器的appearence
属性,或者从零开始设置,你可以自定义这些
常规
shadow
:阴影颜色、偏移、半径和透明度圆角半径
分隔器
:按钮之间以及(标题容器和/或取消按钮)的空间大小和颜色按钮分隔器
:按钮之间的空间大小和颜色
### 标题和消息
标题和消息标题字体颜色
标题和消息标题字体
标题和消息背景
按钮 & 取消按钮
最小按钮高度
按钮标题字体
按钮标题字体颜色
按钮颜色
自定义按钮
特殊按钮,看起来与其他按钮不同。
最小按钮高度
按钮标题字体
按钮标题字体颜色
按钮颜色
安装
通过 CocoaPods
pod 'ANActionSheetController'
手动
下载仓库
将 ANActionSheetController/Source
文件夹或其内容添加到您的项目中
文档
用法
用法与 UIAlertController
相同
首先创建控制器
let actionSheetController = ANActionSheetController.init(title: "a title" , message: "a message")
然后添加操作
actionSheetController.addAction(ANActionSheetNormalAction.init(title: "Button 1", handler: nil))
actionSheetController.addAction(ANActionSheetNormalAction.init(title: "Button 2", handler: nil))
如果您想添加特殊操作 - 与其他操作外观不同的操作 -
var customButtonAppearence = ANActionSheetAppearence.CustomActionAppearence.init()
customButtonAppearence.font = UIFont.init(name: "IntroRustG-Base2Line", size: 17)!
customButtonAppearence.titleColor = UIColor.red
customButtonAppearence.minimumHeight = 10
actionSheetController.addAction(ANActionSheetCustomAction.init(title: "Custom Action", apperarence: customButtonAppearence, handler: nil))
您可以添加一个取消按钮
action.setCancelAction(title: "Cancel Button")
您可以自定义控制器;例如
...
actionSheetController.appearence.actionAppearence.titleColor = UIColor(red:0.929, green:0.922, blue:0.923, alpha: 1.000)
actionSheetController.appearence.actionAppearence.color = UIColor(red:0.69, green:0.714, blue:0.616, alpha: 1.000)
actionSheetController.appearence.buttonSeperatorColor = UIColor.init(red: 0.427, green: 0.498, blue: 0.192, alpha: 1)
...
或者您可能创建一个共享定制
extension ANActionSheetAppearence {
static var aCustomAppearence: ANActionSheetAppearence = {
var customAppearence = ANActionSheetAppearence.init()
customAppearence.actionAppearence.titleColor = UIColor(red:0.929, green:0.922, blue:0.923, alpha: 1.000)
customAppearence.actionAppearence.color = UIColor(red:0.69, green:0.714, blue:0.616, alpha: 1.000)
customAppearence.buttonSeperatorColor = UIColor.init(red: 0.427, green: 0.498, blue: 0.192, alpha: 1)
... and other customizations ...
return customAppearence
}()
}
....
actionSheetController.appearence = ANActionSheetAppearence.aCustomAppearence
....
然后展示它
myController.present(actionSheetController, animated: true, completion: nil)
注意事项
- 您至少应设置一个操作!
- 考虑到操作表可能高于屏幕尺寸(尤其是在横屏手机屏幕上),我使用了 UIScrollView。如果您有更好的解决方案,请提交一个问题。
- 由于视图层次结构,您设置的背景颜色可能看起来与预期不符。例如;如果您将分隔符设置为
蓝色
,而按钮分隔符设置为清除
,则按钮分隔符将显示为蓝色
。
沟通
如果您需要帮助,请提一个问题。如果您发现了错误,请提一个问题。如果您想做出贡献,请提交拉取请求。
许可证
ANActionSheetController 在 MIT 许可证下发布。有关详细信息,请参阅 LICENSE。