EMAlertController 1.0.2

EMAlertController 1.0.2

测试已测试
语言语言 SwiftSwift
许可协议 MIT
发布最后发布2018年10月
SPM支持 SPM

Eduardo Moll 维护。



Icon

Language license CocoaPods GitHub stars CocoaPods

EMAlertController 是 iOS UIAlertController 的一个漂亮的替代品。这个库与原生 UIAlertController 具有一样的实现,并且完全可自定义。

Icon

目录

特性

  • 警报图片(可选)
  • 标题
  • 可滚动消息(可选)
  • 文本字段
  • 按钮按下时的闭包
  • 完全可自定义
  • CocoaPods

要求

  • iOS 9.0+
  • Xcode 9+

安装

CocoaPods 是 Cocoa 项目的依赖管理器。您可以使用以下命令安装:

$ gem install cocoapods

要将 EMAlertController 集成到您的 Xcode 项目中使用 CocoaPods,请在 Podfile 中指定它。

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!

target '<Your Target Name>' do
pod 'EMAlertController'
end

然后,运行以下命令

$ pod install

使用方法

let alert = EMAlertController(title: "EMAlertView Title", message: "This is a simple message for the EMAlertView")

let cancel = EMAlertAction(title: "CANCEL", style: .cancel)
let confirm = EMAlertAction(title: "CONFIRM", style: .normal) {
// Perform Action
}

alert.addAction(action: cancel)
alert.addAction(action: confirm)

自定义

警告视图


图标

let icon = UIImage(named: "imageName")

alert.iconImage = icon

标题

alert.titleText = "Sample Title"

标题颜色

alert.titleColor = UIColor.red
// Default color = UIColor.black

消息

alert.messageText = "Sample message"

消息颜色

alert.messageColor = UIColor.red
// Default color = UIColor.black

消息数据检测类型

alert.dataDetectorTypes = .all

消息可选择性

alert.isMessageSelectable = true
// This must be set to `true` in order to highlight the detected data types

圆角半径

alert.cornerRadius = 10
// Default corner radius = 5

背景颜色

alert.backgroundColor = UIColor.white
// Default color = UIColor(red: 250/255, green: 250/255, blue: 250/255, alpha: 1.0)

背景视图颜色

alert.backgroundViewColor = UIColor.red
// Default color = UIColor.darkGray

背景视图透明度

alert.backgroundViewAlpha = 1.0
// Default alpha = 0.2

警报操作


标题

action.title = "Sample Title"

标题颜色

action.titleColor = UIColor.red
// Normal style action default color = UIColor(red: 53/255, green: 53/255, blue: 53/255, alpha: 1.0)
// Cancel style action default color = UIColor(red: 230/255, green: 57/255, blue: 70/255, alpha: 1.0)

标题字体

action.titleFont = UIFont.systemFont(ofSize: 14)
// Default font = UIFont.boldSystemFont(ofSize: 16)

背景颜色

action.actionBackgroundColor = UIColor.red
// Default color = UIColor.clear

按钮间隔(仅在水平显示两个按钮时)

alert.buttonSpacing = 0
// Default spacing = 15

文本框


添加文本字段

 alert.addTextField { (textField) in
   textField?.placeholder = "Username"
 }

从文本框中获取文本

gaurd let username = alert.textFields.first?.text else { return }

待办事项

  • Carthage 支持
  • 动作滚动支持

许可协议


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