PopupViewController
  • October 29, 2023

UIAlertController drop in replacement with much more customization

You can literally replace UIAlertController by PopupViewController and UIAlertAction by PopupAction and you’re done. Does not support Action Sheet for now, just alert mode.

Simple example.

let alert = PopupViewController(title: “Alert title”, message: “Alert message, which can be very long and etc….”)
alert.addAction(PopupAction(title: “Ok”, type: .positive, handler: nil))
present(alert, animated: true, completion: nil)

Result:

By default it come with a dark theme, but where it become powerful is that you can customize it.

Example:

var customizable = PopupViewController.Customizable()
customizable.titleColor = UIColor.blue
customizable.positiveActionColor = UIColor.red
customizable.messageColor = UIColor.brown
customizable.messageFont = UIFont.boldSystemFont(ofSize: 22)
customizable.negativeActionColor = UIColor.brown
customizable.positiveActionColor = UIColor.blue
customizable.negativeActionBackgroundColor = UIColor.black
customizable.positiveActionBackgroundColor = UIColor.white
customizable.positiveActionHighlightColor = UIColor.green
customizable.negativeActionHighlightColor = UIColor.red

let alert = PopupViewController(title: “Alert title”,
message: “Alert message, which can be very long message and all that but nobody will ever read it.”,
customizable: customizable)
alert.blurStyle = .extraLight
alert.addAction(PopupAction(title: “Ok”, type: .positive, handler: nil))
alert.addAction(PopupAction(title: “Cancel”, type: .negative, handler: nil))
present(alert, animated: true, completion: nil)

Result:

Yes this is very ugly. But you know…

You can also set a static Customizable, it’ll be re used if you pass no customizable in the PopupViewController constructor.

var customizable = PopupViewController.Customizable()
customizable.titleColor = UIColor.blue
customizable.positiveActionColor = UIColor.red
customizable.messageColor = UIColor.brown
customizable.messageFont = UIFont.boldSystemFont(ofSize: 22)
customizable.negativeActionColor = UIColor.brown
customizable.positiveActionColor = UIColor.blue
customizable.negativeActionBackgroundColor = UIColor.black
customizable.positiveActionBackgroundColor = UIColor.white
customizable.positiveActionHighlightColor = UIColor.green
customizable.negativeActionHighlightColor = UIColor.red
PopupViewController.sharedCustomizable = alertCustomizable

Installation


Normal

Add pod 'PopupViewController' in your podfile and then run pod install

Dev mode

Clone this repository and and run pod install in both the PopupViewController and Example directory.

Note

It use the amazing Cartography as a dependency for now because I’m a lazy ass and I don’t want to look at the Apple doc for the ugly Autolayout code hint.

GitHub


View Github

#autolayout #ios #swift #uiviewcontroller
YOU MIGHT ALSO LIKE...
🧭 NavigationKit

NavigationKit is a lightweight library which makes SwiftUI navigation super easy to use. 💻 Installation 📦 Swift Package Manager Using Swift Package Manager, add ...

swiftui-navigation-stack

An alternative SwiftUI NavigationView implementing classic stack-based navigation giving also some more control on animations and programmatic navigation. NavigationStack Installation ...

Stinsen

Simple, powerful and elegant implementation of the Coordinator pattern in SwiftUI. Stinsen is written using 100% SwiftUI which makes it ...

SwiftUI Router

With SwiftUI Router you can power your SwiftUI app with path-based routing. By utilizing a path-based system, navigation in your app becomes ...

FlowStacks

This package takes SwiftUI's familiar and powerful NavigationStack API and gives it superpowers, allowing you to use the same API not just ...