PopupViewController 0.1.5

PopupViewController 0.1.5

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

Thomas Ricouard维护。



UIAlertController的自定义替代品,功能更强大

实际上,您可以简单地用PopupViewController替换UIAlertController,用PopupAction替换UIAlertAction,这样就完成了。目前不支持Action Sheet,只支持alert模式。

简单示例。

  let alert = PopupViewController(title: "Alert title", message: "Alert message, which can be very long and etc....")
  alert.addAction(PopupAction(title: "Ok", type: .positive, handler: nil))
  present(alert, animated: true, completion: nil)

结果

Dark alert

默认情况下,它带有深色主题,但强大之处在于您还可以自定义它。

示例

  var customizable = PopupViewController.Customizable()
  customizable.titleColor = UIColor.blue
  customizable.positiveActionColor = UIColor.red
  customizable.messageColor = UIColor.brown
  customizable.messageFont = UIFont.boldSystemFont(ofSize: 22)
  customizable.negativeActionColor = UIColor.brown
  customizable.positiveActionColor = UIColor.blue
  customizable.negativeActionBackgroundColor = UIColor.black
  customizable.positiveActionBackgroundColor = UIColor.white
  customizable.positiveActionHighlightColor = UIColor.green
  customizable.negativeActionHighlightColor = UIColor.red

  let alert = PopupViewController(title: "Alert title",
                                        message: "Alert message, which can be very long message and all that but nobody will ever read it.",
                                        customizable: customizable)
  alert.blurStyle = .extraLight
  alert.addAction(PopupAction(title: "Ok", type: .positive, handler: nil))
  alert.addAction(PopupAction(title: "Cancel", type: .negative, handler: nil))
  present(alert, animated: true, completion: nil)

结果

Ugly alert

是的,这看起来很丑。但你知道...

您还可以设置一个静态的Customizable,如果您在PopupViewController构造函数中不传递任何自定义控件,它将重复使用。

  var customizable = PopupViewController.Customizable()
  customizable.titleColor = UIColor.blue
  customizable.positiveActionColor = UIColor.red
  customizable.messageColor = UIColor.brown
  customizable.messageFont = UIFont.boldSystemFont(ofSize: 22)
  customizable.negativeActionColor = UIColor.brown
  customizable.positiveActionColor = UIColor.blue
  customizable.negativeActionBackgroundColor = UIColor.black
  customizable.positiveActionBackgroundColor = UIColor.white
  customizable.positiveActionHighlightColor = UIColor.green
  customizable.negativeActionHighlightColor = UIColor.red
  PopupViewController.sharedCustomizable = alertCustomizable

待办事项

  • [ ] 支持Action Sheet
  • [ ] 支持UITextFields
  • [ ] 支持自定义视图
  • [ ] 支持共享自定义配置
  • [ ] 移除cartography依赖关系
  • [ ] 更容易覆盖自定义过渡效果
  • [ ] 更好的默认过渡效果

安装

正常

在您的Podfile中添加pod 'PopupViewController'并运行pod install

开发模式

克隆此仓库,并在PopupViewController和Example目录中运行pod install

注意

由于我是一个懒人,不想查看苹果文档中的丑陋的Autolayout代码提示,目前它使用惊人的Cartography作为依赖项。