TBMAlertController 0.0.10

TBMAlertController 0.0.10

bruce 维护。



  • bruce

teambition

Carthage Compatible CocoaPods Compatible

AlertController

Swift 中的简易且更强大的 AlertController,与 UIAlertController API 兼容。

支持类型

  • alert
  • actionSheet

AlertAction 风格

  • 默认
  • 取消
  • 销毁

要求

  • iOS 9.0

通讯

安装

**嵌入式框架需要至少支持iOS 9的最低部署目标

CocoaPods

CocoaPods 是一个用于Cocoa项目的大型依赖项管理器。您可以使用以下命令安装它

$ gem install cocoapods

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

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

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

然后,运行以下命令

$ pod install

Carthage

Carthage 是一个去中心化的依赖项管理器,它构建您的依赖项并提供二进制框架。

您可以使用以下命令使用 Homebrew 来安装Carthage

$ brew update
$ brew install carthage

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

github "teambition/AlertController"

运行 carthage update 来构建框架

最后,您需要手动设置您的Xcode项目来添加AlertController框架。

在您的应用程序目标“通用”设置选项卡中的“链接框架和库”部分,从磁盘上的Carthage/Build文件夹中拖放您想使用的每个框架。

在您的应用程序目标的“构建阶段”设置选项卡中,单击“+”图标并选择“新建Run Script阶段”。创建一个包含以下内容的Run Script

 /usr/local/bin/carthage copy-frameworks

并将框架的路径添加到“输入文件”下

 $(SRCROOT)/Carthage/Build/iOS/AlertController.framework

有关如何使用Carthage的更多信息,请参阅其项目页面

使用方法

将框架导入到您的类中

Cocoapods

import TBMAlertController

Carthage

import AlertController

添加您的动作代码

 @IBAction func systemActionSheetButtonPressed(_ sender: Any) {
        let title = "System ActionSheet"
        // let message = "A message should be a short, complete sentence."
        let destructiveButtonTitle = "Destructive"
        let otherButtonTitle = "Other Button"
        
        let alertController = UIAlertController(title: title, message: nil, preferredStyle: .actionSheet)
        
        // Create the actions.
        let destructiveAction = UIAlertAction(title: destructiveButtonTitle, style: .destructive) { action in
            print("destructive action")
        }
        
        let normalAction = UIAlertAction(title: "Normal Button", style: .default) { action in
            print("normal action")
        }
        
        let otherAction = UIAlertAction(title: otherButtonTitle, style: .default) { action in
            print("other action")
        }
        
        let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) { action in
            print("cancel action")
        }
        
        // Add the actions.
        alertController.addAction(destructiveAction)
        alertController.addAction(normalAction)
        alertController.addAction(otherAction)
        alertController.addAction(cancelAction)
        
        present(alertController, animated: true, completion: nil)
    }

详情请查看演示

许可证

AlertController是在MIT许可证下发布的。