Ever felt the need to customise the boring default alert provided by iOS using UIAlertController? BBAlert let's you do just that, but not at the cost of loosing functionality of UIAlertController. Since it's build as an typealias of UIAlertController it doesn't require any more of the memory. Package is compiled using Xcode 11.4.1 on MacOS 10.15.4 using Swift 5.2.2 compiler.
import UIKit
import BBAlert
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let actions: [String: UIAlertAction.Style] = [selectedActionText: .default, "Cancel": .cancel]
presentBBAlert(title: "Title", message: "This is a sample message", actions: actions, setup: { alert in
alert.titleFont = .boldSystemFont(ofSize: 20)
alert.messageFont = .systemFont(ofSize: 16)
alert.backgroundColor = Color.allCases[self.selectedBackgroundColorIndex].color
alert.textColor = Color.allCases[self.selectedTextColorIndex].color
}, actionHandler: { action in
if action.title == self.selectedActionText {
print("Selected \(self.selectedActionText)")
}
}) { _ in
print("Perform stuff after completion.")
}
}
}
Animation | Dark mode | Light mode |
The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift
compiler. It is in early development, but BBAlert does support its use on supported platforms.
Once you have your Swift package set up, adding BBAlert as a dependency is as easy as adding it to the dependencies
value of your Package.swift
.
dependencies: [
.package(url: "https://github.com/bibinjacobpulickal/BBAlert.git", .upToNextMajor(from: "1.0.0"))
]
Clone or download the project. Open .xcodeproj
file in Xcode. Change target to iOSExample and run on a device or simulator.
BBAlert is released under the MIT license. See LICENSE for details.