GitXplorerGitXplorer
s

SDCAlertView

public
1860 stars
300 forks
17 issues

Commits

List of commits on branch master.
Unverified
47014c1b6b629761874bb7585951f0c0d90d7823

Update to 12.0.4

ssberrevoets committed 7 months ago
Verified
e45fc536355da8ad64279ea142b229bba87bf0e8

Merge pull request #334 from abdouoi/fix/iOS18

ssberrevoets committed 7 months ago
Verified
28e71bc9cf8e267175e044f10f5270c08c04c819

Fix Transition reference collision with iOS 18 API

aabdouoi committed 7 months ago
Unverified
8d821711afc967b44c74bbd57ba2b2bfeaefb118

Update to 12.0.3

ssberrevoets committed 2 years ago
Verified
8ecca43374f9a6736df69c2ce81b5dda6b8951be

Implement fix for: AlertView offset is not restored after dismissing … (#324)

sscottcwilliams511 committed 2 years ago
Verified
904e119b81d6ac1d3330837307d5bcc46bf41d8b

Merge pull request #330 from ftp27/bg-fix

ssberrevoets committed 2 years ago

README

The README file for this repository.

SDCAlertView

SDCAlertView started out as an alert that looked identical to UIAlertView, but had support for a custom content view. With the introduction of UIAlertController in iOS 8, the project was updated to the more modern API that UIAlertController brought.

Features

  • [x] Most UIAlertController functionality
  • [x] Custom content views
  • [x] Preventing controllers from dismissing when the user taps a button
  • [x] Easy presentation/dismissal
  • [x] Attributed title label, message label, and buttons
  • [x] Appearance customization
  • [x] Usable from Swift and Objective-C
  • [x] Understandable button placement
  • [x] UI tests
  • [x] Custom alert behavior
  • [x] CocoaPods/Carthage/Swift Package Manager support
  • [ ] Easy queueing of alerts

Requirements

  • Swift 5.0
  • iOS 9 or higher

Installation

CocoaPods

To install SDCAlertView using CocoaPods, integrate it in your existing Podfile, or create a new Podfile:

platform :ios, '9.0'
use_frameworks!

target 'MyApp' do
  pod 'SDCAlertView'
end

Then run pod install.

Carthage

To install with Carthage, add the following line to your Cartfile:

github "sberrevoets/SDCAlertView"

Run carthage update and drag SDCAlertView.framework in the Build folder into your project.

Swift Package Manager

To install with Swift Package Manager, add this package to your project’s 'Swift Packages' section. Or add the following line to your Package.swift:

 .package(url: "https://github.com/sberrevoets/SDCAlertView.git", from: "12.0.1")

Alerts vs. Action Sheets

SDCAlertController supports the presentation of action sheets, but there are some limitations and things to keep in mind when using action sheets:

  • It does not properly adapt on iPad. This is because iOS doesn't support UIModalPresentationStyle.Custom for adaptive presentations (such as when presenting an action sheet from a bar button item).
  • The new AlertBehaviors is, due to limitations in the Swift/Objective-C interop, not available when using SDCAlertController from Swift. This affects AlertControllerStyle.Alert as well.
  • When adding subviews to the custom content view, that view will replace the title and message labels.

Usage

SDCAlertView is written in Swift, but can be used in both Swift and Objective-C. Corresponding types in Objective-C have the same name they do in Swift, but with an SDC prefix.

Basic

let alert = AlertController(title: "Title", message: "This is a message", preferredStyle: .alert)
alert.addAction(AlertAction(title: "Cancel", style: .normal))
alert.addAction(AlertAction(title: "OK", style: .preferred))
alert.present()

// or use the convenience methods:

AlertController.alert(withTitle: "Title", message: "This is a message", actionTitle: "OK")
AlertController.sheet(withTitle: "Action sheet title", "Action sheet message", actions: ["OK", "Cancel"])

Custom Content Views

let spinner = UIActivityIndicatorView(activityIndicatorStyle: .gray)
spinner.translatesAutoresizingMaskIntoConstraints = false
spinner.startAnimating()

let alert = AlertController(title: "Title", message: "Please wait...")
alert.contentView.addSubview(spinner)

spinner.centerXAnchor.constraint(equalTo: alert.contentView.centerXAnchor).isActive = true
spinner.topAnchor.constraint(equalTo: alert.contentView.topAnchor).isActive = true
spinner.bottomAnchor.constraint(equalTo: alert.contentView.bottomAnchor).isActive = true

alert.present()

Dismissal Prevention

let alert = AlertController(title: "Title", message: "This is a message")
alert.addAction(AlertAction(title: "Dismiss", style: .preferred))
alert.addAction(AlertAction(title: "Don't dismiss", style: .normal))
alert.shouldDismissHandler = { $0.title == "Dismiss" }
alert.present()

Styling and Appearance

SDCAlertController is a normal view controller, so applying a tintColor to its view will color the buttons and any subviews you add to the contentView.

If you are looking for more customizations, create a subclass of AlertVisualStyle and use visualStyle on the AlertController instance. You can also create an instance of AlertVisualStyle and overwrite the attributes you need (this is mainly intended to be used from Objective-C). Note that after an alert has been presented, changing any of these settings is ignored.

License

SDCAlertView is distributed under the MIT license.