WSAlertController 0.0.2

WSAlertController 0.0.2

Zev 维护。



  • 作者:
  • zevwings

WSAlertController

一个自定义的 Swift 弹出控制器

Carthage compatible CocoaPods Compatible Platform

WSAlertController 是一个纯 Swift、易用的 AlertController。

要求

  • iOS 9.0+
  • Swift 5.0

安装

CocoaPod

CocoaPods 是一个用于 Swift 和 Objective-C Cocoa 项目的依赖管理器。

您可以通过以下命令安装 CocoaPod:

$ sudo gem install cocoapods

要在项目中使用 CocoaPods 集成 WSAlertController,请在您的 Podfile 中指定它。

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'

target 'TargetName' do
    use_frameworks!
    pod 'WSAlertController'
end

然后,使用 CocoaPods 安装您的依赖项。

$ pod install

Carthage

Carthage旨在为应用程序添加框架的最简单方式。

您可以使用以下命令通过Homebrew安装Carthage:

$ brew update
$ brew install carthage

要将WSAlertController集成到您的项目中并使用Carthage,请在您的Cartfile中指定它

github "zevwings/WSAlertController" ~> 0.0.1

然后,使用carthage update通过Carthage构建框架,并将WSAlertController.framework拖动到您的项目中。

注意

框架位于Carthage/Build目录下,您应该将其拖动到“Target” –> “General” –> “Embedded Binaries”下

用法

当您需要使用WSAlertController时,您可以使用导入 WSAlertController。

显示一个Alert

当您启动一个任务时,您可以以下代码中使用

let alertController = WSAlertController(title: "title", message: "message")
present(alertController, animated: true, completion: nil)

您还可以使用以下代码添加alert操作

alertController.addAction(WSAlertAction(title: "confirm", style: .default, handler: { _ in
    print("comfirm action")
}))

您也可以在消息体中使用NSAttributedString

let attributedString = NSMutableAttributedString(string: "message")
attributedString.addAttributes([.foregroundColor: UIColor.cyan], range: NSRange(location: 0, length: 4))
let alertController = WSAlertController(title: "title", message: attributedString)

Props

以下props可以自定义alertController。

public var dismissHandler: DismissHandler?
public var shouldShowDismissButton: Bool = true

public var tintColor: UIColor = .blue
public var positiveColor: UIColor = Constant.positiveColor
public var negativeColor: UIColor = Constant.negativeColor
public var buttonFont: UIFont = .systemFont(ofSize: 14.0)

public var titleColor: UIColor = Constant.titleColor
public var titleFont: UIFont = .systemFont(ofSize: 14.0)

public var messageColor: UIColor = Constant.messageColor
public var messageFont: UIFont = .systemFont(ofSize: 14.0)

许可证

WSAlertAction遵照Apache许可证的条款和条件进行分发