Swift AlertController with UIVisualeffectview

Overview

PCLBlurEffectAlert

Swift AlertController, use UIVisualeffectview

Cocoapods Compatible Swift 3.0

Requirements

  • iOS 8.0+
  • Swift 3.0+
  • ARC

Feature

  • Change color
  • Change effect
  • Change font
  • Use UITextField
  • Use UIImageView

install

Cocoapods

Adding the following to your Podfile and running pod install:

use_frameworks!
pod "PCLBlurEffectAlert"

import

import PCLBlurEffectAlert

Initialize

UIBlurEffect

// Default effect: UIBlurEffect(style: .extraLight)
convenience init(title: String?, message: String?, effect: UIBlurEffect, style: PCLBlurEffectAlert.ControllerStyle)

style => alert, alertVertical, actionSheet

When actions count becomes more than 3, alert and alertVertical is the same as.

Usage

Example

let alertController = PCLBlurEffectAlertController(title: "How are you doing?", 
                                                  message: "Press a button!",
                                                  effect: UIBlurEffect(style: .lightdark)
                                                  style: .alert)'
// Customize if needed
alertController.configure(titleColor: .white)
alertController.configure(buttonFont: [.default: UIFont.systemFont(ofSize: 24),
                                       .destructive: UIFont.boldSystemFont(ofSize: 20),
                                       .cancel: UIFont.systemFont(ofSize: 14)])

// Adds ImageView
alertController.addImageView(with: <image files>)

// Adds TextField
alertController.addTextField()

// Adds actions
let action = PCLBlurEffectAlertAction(title: "I’m fine.", style: .default) { _ in }
let cancelAction = PCLBlurEffectAlertAction(title: "Not so good.", style: .cancel) { _ in }
alertController.addAction(action)
alertController.addAction(cancelAction)

// Presented
alertController.show() // or present(alertController, animated: true, completion: nil)

Sources

// Adds Actions
open func addAction(_ action: PCLBlurEffectAlertAction)
// Adds ImageView
open func addImageView(with image: UIImage, configurationHandler: ((UIImageView?) -> Void)? = nil)
// Adds TextFields
open func addTextField(with configurationHandler: ((UITextField?) -> Void)? = nil)
// Presented
open func show()

Customize

// Default ActionSheet: UIScreen.main.bounds.width - (margin * 2)
// Default Alert: 320 - (margin * 2)
func configure(alertViewWidth: CGFloat)

// Default: 4
func configure(cornerRadius: CGFloat)
// Default: 1 / UIScreen.main.scale
func configure(thin: CGFloat)
// Default: 8
func configure(margin: CGFloat)

/// Color
// Default: UIColor.black.withAlphaComponent(0.3)
func configure(overlayBackgroundColor: UIColor)
// Default: .clear
func configure(backgroundColor: UIColor)

/// Text
// Default: .boldSystemFont(ofSize: 16)
// Default: .black
func configure(titleFont: UIFont, titleColor: UIColor)
// Default: .systemFont(ofSize: 14)
// Default: .black
func configure(messageFont: UIFont, messageColor: UIColor)
// Default: 
// .default: UIFont.systemFont(ofSize: 16),
// .cancel: UIFont.systemFont(ofSize: 16),
// .destructive: UIFont.systemFont(ofSize: 16)
func configure(buttonFont: [PCLBlurEffectAlert.ActionStyle : UIFont])
// Default: 
// .default: .black,
// .cancel: .black,
// .destructive: .red
func configure(buttonTextColor: [PCLBlurEffectAlert.ActionStyle : UIColor])
// Default: 
// .default: .gray,
// .cancel: .gray,
// .destructive: .gray
func configure(buttonDisableTextColor: [PCLBlurEffectAlert.ActionStyle : UIColor])

/// Button
// Default: 44
func configure(buttonHeight: CGFloat)
// Default: .clear
func configure(buttonBackgroundColor: UIColor)

// Default: 32
func configure(textFieldHeight: CGFloat)
// Default: UIColor.white.withAlphaComponent(0.1)
func configure(textFieldsViewBackgroundColor: UIColor)
// Default: UIColor.black.withAlphaComponent(0.15)
func configure(textFieldBorderColor: UIColor)

More Examples

let alertController = PCLBlurEffectAlertController(title: "How are you doing?", 
                                                  message: "Press a button!",
                                                  style: .alert)
let action1 = PCLBlurEffectAlertAction(title: "I’m fine.", style: .default) { _ in }
let action2 = PCLBlurEffectAlertAction(title: "Not so good.", style: .default) { _ in }
alertController.addAction(action1)
alertController.addAction(action2)
alertController.show()

let alertController = PCLBlurEffectAlertController(title: "title title title title title title title",
                                                  message: "message message message message message",
                                                  effect: UIBlurEffect(style: .light),
                                                  style: .alert)
alertController.addTextField { _ in }
alertController.addTextField { _ in }
alertController.configure(textFieldsViewBackgroundColor: UIColor.white.withAlphaComponent(0.1))
alertController.configure(textFieldBorderColor: .black)
alertController.configure(buttonDisableTextColor: [.default: .lightGray, .destructive: .lightGray])
let action1 = PCLBlurEffectAlertAction(title: "Default", style: .default) { _ in }
let action2 = PCLBlurEffectAlertAction(title: "Destructive", style: .destructive) { _ in }
let cancelAction = PCLBlurEffectAlertAction(title: "Cancel", style: .cancel) { _ in }
alertController.addAction(action1)
alertController.addAction(action2)
alertController.addAction(cancelAction)
alertController.show()

let alertController = PCLBlurEffectAlertController(title: "How are you doing?", 
                                                  message: "Press a button!",
                                                  effect: UIBlurEffect(style: .dark),
                                                  style: .actionSheet)
let action1 = PCLBlurEffectAlertAction(title: "I’m fine.", style: .default) { _ in }
let action2 = PCLBlurEffectAlertAction(title: "Not so good.", style: .default) { _ in }
alertController.addAction(action1)
alertController.addAction(action2)
alertController.show()

let alertController = PCLBlurEffectAlertController(title: "title title title title title title title",
                                                  message: "message message message message message",
                                                  style: .actionSheet)
alertController.addTextField()
alertController.addTextField()
alertController.configure(textFieldsViewBackgroundColor: UIColor.white.withAlphaComponent(0.1))
alertController.configure(textFieldBorderColor: .black)
alertController.configure(buttonDisableTextColor: [.default: .lightGray, .destructive: .lightGray])
let action1 = PCLBlurEffectAlertAction(title: "Default", style: .default) { _ in }
let action2 = PCLBlurEffectAlertAction(title: "Destructive", style: .destructive) { _ in }
let cancelAction = PCLBlurEffectAlertAction(title: "Cancel", style: .cancel) { _ in }
alertController.addAction(action1)
alertController.addAction(action2)
alertController.addAction(cancelAction)
alertController.show()

let alertController = PCLBlurEffectAlertController(title: "title title title title title title title",
                                                    message: "message message message message message",
                                                    style: .alert)
alertController.addImageView(with: UIImage(named: "cat")!)
let catAction = PCLBlurEffectAlertAction(title: "Cat?", style: .default) { _ in
    print("You pressed Cat?")
}
let dogAction = PCLBlurEffectAlertAction(title: "Dog?", style: .default) { _ in
    print("You pressed Dog?")
}
alertController.addAction(catAction)
alertController.addAction(dogAction)
alertController.show()

Photos from

Acknowledgements

License

This project is made available under the MIT license. See LICENSE file for details.

Comments
  • "String" is not convertible to "String?"

    I get an error in my title - "String" is not convertible to "String?" on this line:

                let alertController = PCLBlurEffectAlert.Controller(title: "Uh-Oh!", message: error?.localizedDescription, effect: UIBlurEffect, style: .alert)
    

    Would be glad to hear any of your ideas, tried to attach a screenshot here, but GitHub experiences some problems...

    opened by Andriyas123 6
  • Fix broken headings in Markdown files

    Fix broken headings in Markdown files

    GitHub changed the way Markdown headings are parsed, so this change fixes it.

    See bryant1410/readmesfix for more information.

    Tackles bryant1410/readmesfix#1

    opened by bryant1410 1
  • PCLBlurEffectAlertController stack into background mode.

    PCLBlurEffectAlertController stack into background mode.

    When my app goes to background mode and being ideal for some moments then come to foreground mode in result it got stuck and unable to click anywhere.

    Please help.

    opened by pmehul55 0
  • trouble setting buttonTextColor

    trouble setting buttonTextColor

    My code is:

    let alert = PCLBlurEffectAlertController(title: title, message: message, effect: UIBlurEffect(style: .extraLight), style: .alert)

    alert.configure(buttonFont: UIFont.systemFont(ofSize: 24), buttonTextColor: Constant.SLS_SECONDARY_COLOR, buttonDisableTextColor: Constant.SLS_DISABLED_COLOR)

    Getting error on the highlighted part that says, Cannot convert value of type 'UIFont' to expected argument type '[PCLBlurEffectAlert.ActionStyle : UIFont]?'

    Please help, I don't understand what this error means or how to fix.

    opened by jonathan3087 0
  • 毛玻璃

    毛玻璃

    你好,愿不愿意跟我一起探讨一下对话框的毛玻璃问题呢?因为我发现无论是系统,还是微信,微博等,它们的毛玻璃都很漂亮。我说的漂亮是什么意思呢,意思就是毛玻璃不会受到蒙板的影响,我看你的蒙板设置的alpha值是0.3,其实0.3过低了,系统设置的是黑色0.4透明,我看过系统的层级关系图,毛玻璃并未受到蒙板的任何影响,我自己最近也封装了一个https://github.com/SPStore/SPAlertController。 但是不管我怎么设置毛玻璃,因为蒙层的影响,都会偏黑色,我看你的也同样如此。这个问题我已经想了几天几夜了,网上找资料也没人解决过,其实用第三方不是不能实现,但是我不想依赖第三方,而且系统用的也是iOS8自带的UIBlurEffect,只是我不知道系统是如何做到的,我想过用运行时去交换UIVisualEffectView的某个方法,但那么多私有方法,我也不知该重写哪一个。 微信微博和系统的毛玻璃效果都是一致的,能否一起研究一下,我实在遇到困难了。

    opened by SPStore 0
Owner
Hiroyuki Yoshida
Hiroyuki Yoshida
A Simple And Minimalist iOS AlertController

HYAlertController HYAlertController is a minimalist alert control, that contains a variety of usage scenarios. It has the same syntax as Apple's UIAle

null 63 Jul 26, 2022
Swift library to manage in app notification in swift language, like WhatsApp, Telegram, Frind, ecc.

InAppNotify - Manage in App notifications During develop of my app Frind, I needed to manage in app notifications like whatsapp or telegram, but i did

Luca Becchetti 438 Nov 20, 2022
Ipraktikum-swift-solutions - The solutions of the easy entrance swift quiz for the IPraktikum

ipraktikum-swift-solutions The solutions of the easy entrance swift quiz for the

Eugenio Berretta 0 Feb 13, 2022
Highly customizable alertview and alert/notification/success/error/alarm popup written in Swift

CDAlertView is highly customizable alert popup written in Swift. Usage is similar to UIAlertController. Screenshots Animations Usage Basic usage witho

Candost Dagdeviren 1.1k Dec 30, 2022
Easy Swift UIAlertController

EZAlertController Easy Swift UIAlertController One line setup for all UIAlertControllers Button action with closures instead of selectors Easily custo

Kan Yilmaz 366 Sep 14, 2022
A simple style messages/notifications, in Swift.

Demo Example To show notifications use the following code: self.showMessage("Something success", type: .success) To display a notice on a view: view.s

Gesen 704 Dec 17, 2022
A Swift library to provide a bouncy action sheet

Hokusai is a Swift library that provides a bouncy action sheet. It will give the users a fancy experience without taking pains coding the cool animati

Yuta Akizuki 430 Nov 20, 2022
Simple UIAlertController builder class in Swift.

Kamagari Simple UIAlertController builder class in Swift. Features AlertBuilder class to simply build UIAlertController by using method chaining UIAle

Kazunobu Tasaka 78 Nov 29, 2022
A simple, customizable popup dialog for iOS written in Swift. Replaces UIAlertController alert style.

Introduction Popup Dialog is a simple, customizable popup dialog written in Swift. Features Easy to use API with hardly any boilerplate code Convenien

Orderella Ltd. 3.8k Dec 20, 2022
Beautiful animated Alert View. Written in Swift

SCLAlertView Animated Alert View written in Swift, which can be used as a UIAlertView or UIAlertController replacement. Since UIAlertView is deprecate

Viktor Radchenko 5.2k Jan 3, 2023
Live animated Alert View for iOS written in Swift

Sweet Alert iOS Beautiful Animated custom Alert View inspired from javascript library SweetAlert. Written in Swift this SweetAlertView can be used in

Sahil 2k Dec 22, 2022
A Swift library to design custom prompts with a great scope of options to choose from.

Installation CocoaPods Install with CocoaPods by adding the following to your Podfile: source 'https://github.com/CocoaPods/Specs.git' platform :ios,

Gabriel Alvarado 736 Nov 3, 2022
SwiftOverlays is a Swift GUI library for displaying various popups and notifications

SwiftOverlays is a Swift GUI library for displaying various popups and notifications. SwiftOverlays animated logo is kindly made by Crafted Pixels Fea

Peter Prokop 632 Dec 22, 2022
Lightweight dropdown message bar in Swift. It's simple and beautiful.

SwiftyDrop SwiftyDrop is a lightweight pure Swift simple and beautiful dropdown message. Features Easy to use like: Drop.down("Message") Message field

Morita Naoki 691 Nov 20, 2022
Fully customizable and extensible action sheet controller written in Swift

XLActionController By XMARTLABS. XLActionController is an extensible library to quickly create any custom action sheet controller. Examples The action

xmartlabs 3.3k Dec 31, 2022
A Swift Toast view - iOS 14 style and newer - built with UIKit. 🍞

Toast-Swift A Swift Toast view - iOS 14 style - built with UIKit. ?? Installation Swift Package Manager You can use The Swift Package Manager to insta

Bastiaan Jansen 216 Jan 4, 2023
Bursts 🔥 A Funny Framework is showing alerts, Have been Adapting Swift and SwiftUI

Bursts ?? A Funny Framework is showing alerts, Have been Adapting Swift and SwiftUI Features iOS 10+ Can be used in UIKit and SwiftUI applications Lig

Jovins 11 Apr 22, 2022
A Swift package for iOS/tvOS for easy alert presentation

AlertPresenter Listed on the Swift Package Index and originally posted on my blog. It can be fiddly to handle the presentation of alerts on a specific

Chris Mash 14 Jul 1, 2022
Awesome iOS 11 appstore cards in swift 5.

Cards brings to Xcode the card views seen in the new iOS XI Appstore. Getting Started Storyboard Go to main.storyboard and add a blank UIView Open the

Paolo Cuscela 4.1k Dec 14, 2022