NewYorkAlert

NewYorkAlert is a modern alert and action sheet for iOS written in Swift.

alert action_sheet text_fields alert_dark--1-

Features

  • [x] Modern design
  • [x] Easy to add text fields and image
  • [x] Support dark mode
  • [x] Can be dismissed via background tap

Requirements

  • Swift 5.1
  • iOS 11.0 or later

Usage

API Documentation

Default Alert

let alert = NewYorkAlertController(title: "Title", message: "Message", style: .alert)

let ok = NewYorkButton(title: "OK", style: .default) { _ in
    print("Tapped OK")
}
let cancel = NewYorkButton(title: "Cancel", style: .cancel)

alert.addButton(ok)
alert.addButton(cancel)

present(alert, animated: true)

Default Action Sheet

let actionSheet = NewYorkAlertController(title: "Title", message: "Message", style: .actionSheet)

let buttons = [
    NewYorkButton(title: "Apple", style: .default),
    NewYorkButton(title: "Orange", style: .default),
    NewYorkButton(title: "Lemon", style: .default),
]
actionSheet.addButtons(buttons)

present(actionSheet, animated: true)

Text Fields (Only Alert)

let alert = NewYorkAlertController.init(title: "Title", message: "Message", style: .alert)

alert.addTextField { tf in
    tf.placeholder = "username"
    tf.tag = 1
}
alert.addTextField { tf in
    tf.placeholder = "password"
    tf.tag = 2
}

let ok = NewYorkButton(title: "OK", style: .default) { [unowned alert] _ in
    alert.textFields.forEach { tf in
        let text = tf.text ?? ""
        switch tf.tag {
        case 1:
            print("username: \(text)")
        case 2:
            print("password: \(text)")
        default:
            break
        }
    }
}
let cancel = NewYorkButton(title: "Cancel", style: .cancel)
alert.addButtons([ok, cancel])

present(alert, animated: true)

Dark Mode

NewYorkAlert will automatically follow an app's user interface style.

alert_dark action_sheet_dark text_fields_dark

Installation

CocoaPods

Add the following to your Podfile:

pod 'NewYorkAlert'

Carthage

Add the following to your Cartfile:

github "shiba1014/NewYorkAlert"

GitHub