Skip to content

phimage/AlertController

Repository files navigation

AlertController

License Platform Language Issues Cocoapod

A NSViewController to display an alert message to the user. This class replaces the NSAlert class and is inspired from UIAlertController.

After configuring the alert controller with the actions and style you want, present it using presentViewControllerAsSheet.

let controller = AlertController(title: "Alert title", message: "An alert message", preferredStyle: .warning)
parentVC.presentViewControllerAsSheet(controller)

## Usage

Add a simple dismiss action

controller.add(action: AlertAction.dismiss(for: controller, title: "Ok"))

Add custom action

controller.add(action: AlertAction(title: "Report...") { action in
    NSWorkspace.shared().open(URL(string: "https://github.com/phimage/AlertController/issues")!)
})

Choose a style

controller.addAction(title: "", style: .helpButton) { action in
    // show error help
}

Customize buttons bar

controller.buttonsBar.color = NSColor.red
controller.buttonsBar.buttonSpace = 8

Todo

  • More customization
    • align buttons left or right
    • automatic helpButton on left
  • Maybe input text fields

Installation

Using CocoaPods

CocoaPods is a centralized dependency manager for Objective-C and Swift. Go here to learn more.

  1. Add the project to your Podfile.

    use_frameworks!
    
    pod 'NSAlertController'
  2. Run pod install and open the .xcworkspace file to launch Xcode.

Using Carthage

github 'phimage/AlertController'

About

An NSViewController to display an alert message to the user. This class replaces the NSAlert class.

Resources

License

Stars

Watchers

Forks

Packages

No packages published