测试已测试 | ✓ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布上次发布 | 2017年1月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✓ |
由 Jeremiah Jessel 维护。
JHTAlertController 是一个易于使用的 UIAlertController
替代方案。您可以根据应用主题自定义警报的外观。
// Setting up an alert with a title and message
let alertController = JHTAlertController(title: "Turtle", message: "In this alert we use a String for the title instead of an image.", preferredStyle: .alert)
// Create the action.
let cancelAction = JHTAlertAction(title: "Cancel", style: .cancel, handler: nil)
// Create an action with a completionl handler.
let okAction = JHTAlertAction(title: "Ok", style: .default) { _ in
print("Do something here!")
}
// Add the actions to the alert.
alertController.addAction(cancelAction)
alertController.addAction(okAction)
// Show the action
present(alertController, animated: true, completion: nil)
// Change the background color
alertController.alertBackgroundColor = .black
// Round the corners
alertController.hasRoundedCorners = true
// Use an image instead of text
alertController.titleImage = UIImage(named: "Turtle")
// If you add an image to the title block, you may need to set restrictTitleViewHeight to true, depending on the image size
// Change the color of the text
alertController.titleTextColor = .black
// Change the font
alertController.titleFont = .systemFont(ofSize: 18)
// Change the title block color
alertController.titleViewBackgroundColor = .black
// Add an icon image to the title block
let alertController = JHTAlertController(title: "Wow!", message: "You can even set an icon for the alert.", preferredStyle: .alert, iconImage: UIImage(named: "TurtleDark"))
// Change the font
alertController.messageFont = .systemFont(ofSize: 18)
/ Change thte text color
alertController.messageTextColor = .black
// Change the color of the divider
alertController.dividerColor = .black
// Change the color of the button during the creation of the action
let blueAction = JHTAlertAction(title: "Blue", style: .default, bgColor: .blue, handler: nil)
// Change the color for all buttons of a specific action
alertController.setButtonBackgroundColorFor(.default, to: .blue)
// Change the text color for a specific action
alertController.setButtonTextColorFor(.default, to: .white)
// Change the font for a specific action
alertController.setButtonFontFor(.default, to: .systemFont(ofSize: 18))
// Change all action types to a specific color
alertController.setAllButtonBackgroundColors(to: .blue)
要运行示例项目,请克隆代码仓库,然后首先从 Example 目录运行 pod install
。
iOS 9.0 及更高版本
Jeremiah Jessel @ Jacuzzi Hot Tubs, LLC
JHTAlertController 可在 MIT 许可证下获取。有关更多信息,请参阅 LICENSE 文件。