JSSAlertView 5.0.2

JSSAlertView 5.0.2

测试已测试
语言语言 SwiftSwift
许可 MIT
发布上次发布2019年12月
SPM支持 SPM

Tomas Sykora 维护。



  • Jay Stakelon 和 Tomas Sykora,jr.

JSSAlertView

Swift5 Swift4.2 Swift4 Swift3 Swift2 Build Status Carthage compatible Version License Platform

SWIFT 版本!

对于 Swift 5,使用

pod 'JSSAlertView'

对于 Swift 4.2,使用

pod 'JSSAlertView', '~> 4.2.0'

对于 Swift 4,使用

pod 'JSSAlertView', '~> 4.0.0'

对于 Swift 3,使用

pod 'JSSAlertView', '~> 3.0.4'

对于 Swift 2,使用

pod 'JSSAlertView', '~> 1.1.5'

为 iOS 7+ 编写的自定义 "模态" 提示框,用 Swift 实现,包含一些基本主题,并支持自定义图标和字体。灵感来自并仿照了 vikmeupSCLAlertView

BackgroundImage

在 Cocoapods 上尝试

pod try JSSAlertView

在克隆仓库上尝试

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

安装

Cocoapods

JSSAlertView 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile

pod 'JSSAlertView'

Carthage

Carthage 是一个去中心化的依赖管理器,它构建您的依赖并为您提供二进制框架。需要至少 0.17 版本。

要安装,只需将以下行添加到您的 Cartfile

github "JSSAlertView/JSSAlertView"

使用

请确保您使用以下方式导入 JSSAlertView

import JSSAlertView

最简化的警告只需要一个标题。

JSSAlertView().show(
  self, // the parent view controller of the alert
  title: "I'm an alert" // the alert's title
)

延时警告

JSSAlertView().show(
  self, // the parent view controller of the alert
  title: "I'm an alert", // the alert's title
  delay: 3 // time in secs
)

您需要首先传递要添加overlay和alert子视图的视图控制器的引用。

除了默认的 show() 方法之外,您还可以调用四个警告主题中的任何一个:info()success()warning()danger()

JSSAlertView().success(
  self,
  title: "Great success",
  text: "This is the built-in .success style"
)

您可以自定义按钮文本,添加自定义图标并自定义警告颜色。

var customIcon:UIImage! // your custom icon UIImage
var customColor:UIColor! // base color for the alert
JSSAlertView().show(
  self,
  title: "Another alert",
  text: "An alert with more customizations.",
  buttonText: "Right on",
  color: customColor,
  iconImage: customIcon)

您还可以通过传递参数 noButtons: true 来决定不显示任何按钮,这样 JSSAlerView 就会在点击时关闭并发送关闭回调。

JSSAlertView().show(
	self,
	title: "Custom color",
	text: "All of the cool kids have purple alerts these days",
	buttonText: "Whoa",
	color: UIColorFromHex(0x9b59b6, alpha: 1))

您还可以提供一个在警告消失后运行的回调函数,指定自定义字体并将警告的文本颜色从暗色变为亮色。

func myCallback() {
  // this'll run after the alert is dismissed
}
var alertview = JSSAlertView().show(self,
  title: "Yet another alert",
  text: "Callbacks, fonts and text colors"
)
alertview.addAction(myCallback) // Method to run after dismissal
alertview.setTitleFont("ClearSans-Bold") // Title font
alertview.setTextFont("ClearSans") // Alert body text font
alertview.setButtonFont("ClearSans-Light") // Button text font
alertview.setTextTheme(.Light) // can be .Light or .Dark

最后,通过传递一些 cancelButtonText,可以实现具有左侧取消按钮的二按钮警告。警告左侧的按钮将反映该文本,在点击时简单关闭警告,可选取消回调。右侧的按钮也会像往常一样关闭警告,如果存在适当的关闭回调。

func myCancelCallback() {
  // this'll run if cancel is pressed after the alert is dismissed
}
var alertview = JSSAlertView().show(
  self,
  title: "I'm an alert",
  text: "An alert with two buttons. Dismiss by tapping the left, and do something else by tapping the right.",
  buttonText: "OK",
  cancelButtonText: "Cancel" // This tells JSSAlertView to create a two-button alert
)
alertview.addCancelAction(myCancelCallback)

更多示例,请参阅附带的示例项目。

作者

初始作者为Jay Stakelon http://stakelon.com

当前维护者为Tomas Sykora, jr. http://syky.cz

许可证

JSSAlertView遵循MIT许可证。有关更多信息,请参阅LICENSE文件。