HYAlertController 1.0.2

HYAlertController 1.0.2

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

hyyy 维护。



  • Hyyy

HYAlertController

HYAlertController 是一个极简的警告控制器,包含多种使用场景。它的语法与 Apple 的 UIAlertController 相同,因此您可以在自己的应用程序中轻松使用它。

中文说明

警告样式

Icon Icon

表单样式

Icon Icon

共享样式

Icon

功能

  • [x] 标题
  • [x] 描述信息(自适应高度)
  • [x] 带图标的按钮
  • [x] 默认包含取消按钮
  • [x] 新的共享样式
  • [x] 按钮 点击时的闭包
  • [x] 与 UIAlertController 类似的语法
  • [x] 支持 Swift 3
  • [x] Cocoapods
  • [ ] Carthage

需求

  • Swift 3
  • iOS 10.0+
  • Xcode 8+

手动

下载并将 /HYAlertController 文件夹拖放到您的项目中。

用法

用法与 UIAlertController 非常相似。《HYAlertController》有三种样式:警告、表单和共享。

警告样式:用此样式,您可以将显示内容居中,作为对话框的提示用户操作;

表单样式:用此样式,您可以将显示内容显示在屏幕底部,以下将弹出对话框供用户选择;

共享样式:类似于 表单样式,区别在于此样式可用于共享功能,您可以快速完成主流共享样式的创建。

警告样式

//Work with Swift 3

let alertVC: HYAlertController = HYAlertController (title: "Title", message: "Here you can describe the details of its title, and you can write here what you want to express.", style: .alert)
let oneAction: HYAlertAction = HYAlertAction (title: "One Action", style: .normal, handler:  { (action) in
    print(action.title)
})
let twoAction: HYAlertAction = HYAlertAction (title: "Two Action", style: .normal, handler:  { (action) in
    print(action.title)
})
let threeAction: HYAlertAction = HYAlertAction (title: "Three Action", style: .destructive, handler:  { (action) in
    print(action.title)
})
let cancelAction: HYAlertAction = HYAlertAction (title: "Cancel Action", style: .cancel, handler:  { (action) in
    print(action.title)
})
alertVC.addAction(action: oneAction)
alertVC.addAction(action: twoAction)
alertVC.addAction(action: threeAction)
alertVC.addAction(action: cancelAction)
self.present(alertVC, animated: true, completion: nil)

表单样式

//Work with Swift 3

let alertVC: HYAlertController = HYAlertController (title: "Title", message: "Here you can describe the details of its title, and you can write here what you want to express.", style: .actionSheet)
let oneAction: HYAlertAction = HYAlertAction (title: "One Action", style: .normal, handler:  { (action) in
    print(action.title)
})
let twoAction: HYAlertAction = HYAlertAction (title: "Two Action", style: .normal, handler:  { (action) in
    print(action.title)
})
let threeAction: HYAlertAction = HYAlertAction (title: "Three Action", style: .destructive, handler:  { (action) in
    print(action.title)
})
let cancelAction: HYAlertAction = HYAlertAction (title: "Cancel Action", style: .cancel, handler:  { (action) in
    print(action.title)
})
alertVC.addAction(action: oneAction)
alertVC.addAction(action: twoAction)
alertVC.addAction(action: threeAction)
alertVC.addAction(action: cancelAction)
self.present(alertVC, animated: true, completion: nil)

共享样式

//Work with Swift 3
let alertVC: HYAlertController = HYAlertController (title: nil, message: nil, style: .shareSheet)
let oneAction: HYAlertAction = HYAlertAction (title: "Facebook", image: UIImage (named: "facebook")!, style: .normal, handler: {
            (action) in
    print(action.title)
})
let twoAction: HYAlertAction = HYAlertAction (title: "Twitter", image: UIImage (named: "twitter")!, style: .normal, handler: {
            (action) in
    print(action.title)
})
let threeAction: HYAlertAction = HYAlertAction (title: "Snapchat", image: UIImage (named: "snapchat")!, style: .normal, handler: {
            (action) in
    print(action.title)
})
let fourAction: HYAlertAction = HYAlertAction (title: "Instagram", image: UIImage (named: "instagram")!, style: .normal, handler: {
            (action) in
    print(action.title)
})
let fiveAction: HYAlertAction = HYAlertAction (title: "Pinterest", image: UIImage (named: "pinterest")!, style: .normal, handler: {
            (action) in
    print(action.title)
})
let sixAction: HYAlertAction = HYAlertAction (title: "Line", image: UIImage (named: "line")!, style: .normal, handler: {
            (action) in
    print(action.title)
})
alertVC.addShareActions(actions: [oneAction, twoAction, threeAction, fourAction, fiveAction, sixAction])
self.present(alertVC, animated: true, completion: nil)

有关更多用法场景,请参阅《HYAlertControllerDemo》以获取详细信息。

Swift 版本

《HYAlertController》是用 Swift 3 开发的,因此您的 Swift 版本必须是 Swift 3。

自定义

HYAlertController 不提供外部定制,这与开发者想法相关。如果想做一些基本更改,请下载项目源代码,并修改HY_Constants.swift文件,其中包含一些基本设置常量,对其进行修改。

修改后,可以使用上述手动安装方法将其集成到您的项目中。

沟通

  • 如果您需要帮助或想提出一般性问题,请提交一个问题;
  • 如果您发现了错误,请提交一个问题;
  • 如果您有一个功能请求,请提交一个问题;
  • 如果您想做出贡献,请提交一个拉取请求。

MIT 许可

HYAlertController 在MIT 许可下可用。有关更多信息,请参阅LICENSE文件。