JESAlertView 2.0.7

JESAlertView 2.0.7

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

JerryShi 维护。



  • Jerry Shi

JESAlertView

支持 Swift 3🎉

JESAlertView 是用 Swift 3 写的 alert view,支持动作表和 alert view 样式。

现在提供 6 种样式来显示你的 alert。

如果你想要使用 Swift 3 的世界,你需要 Xcode 8+。

2.0.1 版本中的新特性

重新设计了代码和 API,现在提供比 2.0.0 版本之前更方便的方式来使用 JESAlertView,例如 SnapKit🎉

截图

GIF GIF

易于使用

提供了一个默认的 alert view 主题。因此,您可以使用此默认主题或创建一个您喜欢的主题。

import JESAlertView

2.0.1 之前

// 🌟 Usage 👇
let theme = JESAlertViewTheme.defaultTheme()
let alert = JESAlertView(withTheme: theme, 
                    preferredStyle: .alert(category: .normal), 
                             title: "A customizable action sheet title.", 
                           message: "A customizable action sheet message.", 
                      cancelButton: .cancel("CANCEL"),
                 destructiveButton: .destructive("OK"), 
                      otherButtons: [.customize("Default 1",
                                   UIColor.whiteColor(),
UIColor(red: 80 / 255.0, green: 227 / 255.0, b: 194 / 255.0, alpah: 1.0))], 
                        tapClosure: { (index) in
                            print("Tapped button index is \(index)")
                    })
// Show Alert view
presentViewController(alert, animated: true, completion: nil)

2.0.1 之后

self.jes.presentAlert(animated: true, { (make) in
    make.theme
        .actionSheet
        .title("Okay/Cancel")
        .message("A customizable action sheet message.")
        .cancel("Cancel")
        .destructive("OK")
        .normal([])
        .tapped({ (index) in
            print("Tapped index is \(index)")
        })
})  

使用自定义主题

self.jes.presentAlert(animated: true, { (make) in
    make.customize
        .theme(theme)
        .actionSheet
        .title("Okay/Cancel")
        .message("A customizable action sheet message.")
        .cancel("Cancel")
        .destructive("OK")
        .normal([])
        .tapped({ (index) in
            print("Tapped index is \(index)")
        })
})  

有关更多使用方法,请参阅 此处

自定义主题

您可以为它创建一个主题,使 alert view 和以前不同。如下所示:

2.0.1 之前

JESAlertViewTheme(overlayColor: UIColor.overlayColor,
                    titleFont: UIFont.boldSystemFontOfSize(18),
                   buttonFont: UIFont.boldSystemFontOfSize(16),
                  messageFont: UIFont.systemFontOfSize(16),
               titleTextColor: UIColor.textColor,
             messageTextColor: UIColor.textColor,
              backgroundColor: UIColor.backgroundColor,
                        shape: .Rounded(2.0))

形状

public typealias CornerRadius = CGFloat
public enum AlertShape {
    case squared
    case rounded(CornerRadius)
}

2.0.1 之后

2.0.1 之后,我们可以修改默认属性,如下所示:

let theme = AlertTheme.theme.backgroundColor(UIColor.black).buttonBackgroundColor(UIColor.red)
            .buttonTitleFont(UIFont.systemFont(ofSize: 14))

所有主题属性都在这里

var overlayColor: UIColor
var backgroundColor: UIColor

var titleFont: UIFont
var titleColor: UIColor
var messageFont: UIFont
var messageColor: UIColor

var buttonTitleFont: UIFont
var buttonTitleColor: UIColor
var buttonBackgroundColor: UIColor

var cancelButtonBackgroundColor: UIColor
var cancelButtonTitleColor: UIColor

var destructBackgroundColor: UIColor
var destructTitleColor: UIColor

var shape: AlertShape

安装

JESAlertView 通过 Cocoapods 提供。

将以下内容添加到您的 Podfile 中:

pod 'JESAlertView', '~> 2.0.1'

版本 1.0.1 中的新增功能

截图

GIF

提供了更多 alert view 的样式。

用法

2.0.1 之前

let actionSheet = JESAlertView(withTheme: theme, 
                          preferredStyle: .alert(category: .success), 
                                   title: "Congratulations!", 
                                 message: "You've just displayed this awesome Pop Up View.", 
                            cancelButton: .cancel("CANCEL"), 
                            otherButtons: [.defaultStyle("Default 1"), .DefaultStyle("Default 2")], 
                              tapClosure: { (index) in              
                                print("Tapped button index is \(index)")
                 })
presentViewController(actionSheet, animated: true, completion: nil) 

升级 JESAlertViewStyle

public enum JESAlertViewStyle {
    case actionSheet
    case alert(category: JESAlertViewCategory)
}

创建一个名为 JESAlertViewCategory 的枚举

public enum JESAlertViewCategory {
    case normal, success, failure, warning, notice, question
}

2.0.1 之后

self.jes.presentAlert(animated: true, { (make) in
    make.theme
        .alert
        .success
        .title("Congratulations!")
        .message("You've just displayed this awesome Pop Up View.")
        .cancel("Cancel")
        .normal(["Default 1", "Default 2"])
        .tapped({ (index) in
            print("Index \(index)")
        })
})

图标图像来源于 SCLAlertView

待办

  • [ ] 更多动画
  • [ ] 将自定义视图显示到窗口上
  • [ ] 更优美的语法
  • [x] 使用方法类似于 SnapKit

许可协议

JESAlertView 采用 MIT 许可协议发布。请参阅 LICENSE 获取详细信息。