Native alert from Apple Music & Feedback. Contains Done, Heart & Message and other presets.

Last update: Aug 11, 2022

SPAlert

Popup from Apple Music & Feedback in AppStore. Contains Done, Heart, Error and other presets. Supports Dark Mode. I tried to recreate Apple's alerts as much as possible. You can find these alerts in the AppStore after feedback and after you add a song to your library in Apple Music.

You can create more with custom images and SFSymbols more:

If you like the project, don't forget to put star ★ and follow me on GitHub:

https://github.com/ivanvorobei

Navigate

Installation

Ready for use on iOS 11+. Works with Swift 5+. Required Xcode 12.5 and higher.

Swift Package Manager

The Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.

To integrate SPAlert into your Xcode project using Xcode 12, specify it in File > Swift Packages > Add Package Dependency...:

https://github.com/ivanvorobei/SPAlert

CocoaPods:

CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate SPAlert into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'SPAlert'

Manually

If you prefer not to use any of dependency managers, you can integrate SPAlert into your project manually. Put Sources/SPAlert folder in your Xcode project. Make sure to enable Copy items if needed and Create groups.

Quick Start

For best experience, I recommend presenting alerts by calling the class functions SPAlert. These functions are updated regularly and show the alerts as Apple way:

SPAlert.present(title: "Added to Library", preset: .done)

For using a custom image:

SPAlert.present(title: "Love", message: "We'll recommend more like this in For You", preset: .custom(UIImage.init(named: "heart")!))

For showing a simple text message:

SPAlert.present(message: "Something going wrong", haptic: .error)

Usage

Duration

For change duration of present time, create alert view and call present method with custom duration:

let alertView = SPAlertView(title: "Complete", preset: .done)
alertView.present(duration: 3)

Layout

For customise layout and margins, use layout property. You can manage margins for each side, icon size and space between image and titles:

alertView.layout.iconSize = .init(width: 24, height: 24)
alertView.layout.margins.top = 12
alertView.layout.spaceBetweenIconAndTitle = 8

Dismiss by Tap

If you tap the alert, it will disappear. This can be disabled:

alertView.dismissByTap = false

Haptic

For manage haptic, you shoud pass it in present method:

alertView.present(duration: 1.5, haptic: .success, completion: nil)

You can remove duration and completion, its have default values.

Other Projects

SPPermissions

Using for request and check state of permissions. Available native UI for request multiple permissions at the same time. Simple integration and usage like 2 lines code.

SPPerspective

Animation of widgets from iOS 14. 3D transform with dynamic shadow. Video preview. Available deep customisation 3D and shadow. Also you can use static transform without animation.

SPDiffable

Simplifies working with animated changes in table and collections. Apple's diffable API required models for each object type. If you want use it in many place, you pass time to implement it and get over duplicates codes. This project help do it elegant with shared models and special cell providers. Support side bar iOS14 and already has native cell providers and views.

SparrowKit

Collection of native Swift extensions to boost your development. Support tvOS and watchOS.

SPIndicator

Floating indicator, mimicrate to indicator which appear when silent mode turn on / off. Support large texts and has ready-use animatable icons like done and error.

Russian Community

В телеграм-канале Код Воробья пишу о iOS разработке. Помощь можно найти в нашем чате. Видео-туториалы выклыдываю на YouTube:

Tutorials on YouTube

GitHub

https://github.com/ivanvorobei/SPAlert
Comments
  • 1. Color for icon in SwiftUI

    Is your feature request related to a problem? Please describe. Please add custom color support to icons in SwiftUI.

    Describe the solution you'd like Something, where you can define the color of the .error icon animation. It would be pretty nice!

    Reviewed by derech1e at 2021-12-20 17:10
  • 2. Add new type of alert — Loading Alert

    If you think it's a bad idea to add a loading option, then let's discuss it, maybe you should simply open some of the SPAlert.swift API so anyone using your project can subclass and add things easily.

    Also, I noticed that when dark mode is enabled + multitasking on iPad, the blurred background is a little bit weird but I didn't find a solution yet.

    Last but not least, why you prefered going with some frame calculation instead of using the auto-layout magic?

    Reviewed by mlouli at 2020-03-17 21:59
  • 3. Loading View

    Hi,

    I suggested a Loading View a few months back and you pointed me to this repo mlouli/SPAlert

    I grabbed his changes but also made a few of my own

    you can show a alert in a simple yet fast way

    let alert = SPAlert.presentLoader(message: "Loading...")
    alert.dismis()
    

    If you want using the timeout it's also possible

    let _ = SPAlert.presentLoader(message: "Loading...", timeout: 5)
    

    by default it makes the loading view as a rectangle, this is a preference of my own, but you may disable this option by

    let loadingView = SPAlertView(loadingMessage = "Loading...")
    loadingView.makeLoadingViewRectangular = false
    loadingView.present()
    

    this way it will use the normal calculations.

    I also updated the README.md to include this changes.

    This library was tested in SwiftUI and found no errors

    Reviewed by PedroCavaleiro at 2020-04-08 16:33
  • 4. Alert appears behind keyboard if the keyboard is open.

    I'm using SPAlert in a passcode view. Whenever a user enters an incorrect password, SPAlert will show an alert message with an icon. However, the alert appears partly behind the keyboard that is open.

    Is there any layout option that resolves this?

    Version in use: 1.1.1

    Reviewed by tijme at 2019-08-24 16:10
  • 5. Is it possible that we can display things other than images inside the alert?

    Hi @ivanvorobei

    I'm trying to use this SPAlert to display a loading indicator, but for now, it only accepts a couple of default presets and a custom UIImage. Is there any changes that we could pass something like CAShapeLayer in it? For example https://github.com/relatedcode/ProgressHUD/blob/master/ProgressHUD/Sources/ProgressHUD.swift#L743-L785

    I know I can probably address this with a custom loading image. But with so many different screen resolutions, I'm not sure if it's a good idea to go about :(

    Thanks for creating and publishing OSS like this :)

    Reviewed by konekoya at 2021-10-13 03:33
  • 6. Xcode 13 beta 3: 'shared' is unavailable in application extensions for iOS

    Describe the bug The package won't compile in latest Xcode 13.0 beta 3 using SPM. It seems that the latest compiler requires us to mark present(...) as @available(iOSApplicationExtension, unavailable) explicitly since UIApplication.shared is unavailable in extension target. Even though we don't have any extension target.

    // SPAlertView.swift
    
        open func present(duration: TimeInterval = SPAlertConfiguration.duration, haptic: SPAlertHaptic = .success, completion: (() -> Void)? = nil) {
            
            if self.presentWindow == nil {
                self.presentWindow = UIApplication.shared.keyWindow // <=== 👀 Error: 'shared' is unavailable in application extensions for iOS: Use view controller based solutions where appropriate instead.... 'shared' has been explicitly marked unavailable here (UIKit.UIApplication)
            }
            
            guard let window = self.presentWindow else { return }
            
            window.addSubview(self)
            
            // Prepare for present
            // ...
            
    

    To Reproduce

    1. Create a new iOS project in Xcode, and add SPAlert in Package Dependencies.
    2. Add SPAlert library to iOS target.
    3. Compile.

    Expected behavior No error like in Xcode 12.

    Smartphone (please complete the following information):

    • Xcode version 13.0 beta 3
    • SPAlert version 3.2.4
    • Installed via SPM
    Reviewed by gongzhang at 2021-07-18 23:47
  • 7. layout.bottomSpace no longer accessible

    Hi, why is the following property no longer accessible?

    alertView.layout.bottomSpace = UIScreen.main.bounds.height
    alertView.layout.topSpace = UIScreen.main.bounds.height
    

    so I could have it displayed very well in full screen above everything.

    Thanks

    Reviewed by salvatoreboemia at 2021-02-27 09:36
  • 8. is this completion handler or button action possible?

    This is very nice library but would like to have completion handler once animation done.

    as well would be great if it has buttons in the alert to handle some actions

    Reviewed by chetandobariya at 2020-07-26 19:35
  • 9. I needed to add a delegate or a completionHandler for when animation is done

    Hi,

    Very nice library, I was just a bit suprised because the library didn't have a delegate that is triggered when the animation is complete. I am hoping something like this could be added so I can integrate the library using Swift Package Manager.

        /**
         Use this method for force dismiss controller. By default it call automatically.
         */
        @objc public func dismiss() {
            UIView.animate(withDuration: 0.2, animations: {
                self.alpha = 0
                self.transform = self.transform.scaledBy(x: 0.8, y: 0.8)
            }, completion: { finished in
                self.delegate?.didFinishAnimation()
                self.removeFromSuperview()
            })
        }
    
    or adding a completionHandler
        public func present(completionHandler: @escaping (() -> Void)) {
            haptic.impact()
            keyWindow.addSubview(self)
            layoutIfNeeded()
            layoutSubviews()
            alpha = 0
            transform = transform.scaledBy(x: 0.8, y: 0.8)
    
            UIView.animate(withDuration: 0.2, animations: {
                self.alpha = 1
                self.transform = CGAffineTransform.identity
            }, completion: { _ in
                if let iconView = self.iconView as? SPAlertIconAnimatable {
                    iconView.animate()
                }
                DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + self.duration) {
                    self.dismiss(completionHandler: completionHandler)
                }
            })
        }
    
    Reviewed by waelsaad at 2020-06-22 02:43
  • 10. Set dismissByTap to false is not working

    Describe the bug tapGesterRecognizer is initialized before dismissByTap is set to false.

    To Reproduce

    let alertView = SPAlertView(title: "", preset: .spinner) // tapGesture is added to view
    alertView.dismissByTap = false // will not work
    alertView.present()
    

    CleanShot 2021-11-30 at 19 54 21

    Reviewed by hstdt at 2021-11-30 11:56
  • 11. Add NSAttributedString present

    Goal

    Added SPAlert method present(message: NSAttributedString, haptic: SPAlertHaptic, completion: (() -> Void)? = nil)

    Checklist

    • [ ] Testing in iOS
    • [ ] Installed correct via Swift Package Manager and Cocoapods
    Reviewed by viktart at 2021-09-06 20:11
Lightweight dropdown message bar in Swift. It's simple and beautiful.
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

Jun 29, 2022
A message bar for iOS written in Swift.
A message bar for iOS written in Swift.

Dodo, a message bar for iOS / Swift This is a UI widget for showing text messages in iOS apps. It is useful for showing short messages to the user, so

Jul 12, 2022
A message bar for iOS written in Swift.
A message bar for iOS written in Swift.

Dodo, a message bar for iOS / Swift This is a UI widget for showing text messages in iOS apps. It is useful for showing short messages to the user, so

Jul 12, 2022
A crisp in-app notification/message banner built in Swift.
A crisp in-app notification/message banner built in Swift.

RMessage Screenshots Intro Welcome to RMessage! RMessage is a simple notification library written in Swift to help you display notification on the scr

Jul 25, 2022
(Experimental libraries) Controls interrupt handling, such as alert views, and is compatible with UIKit and Swift UI.
(Experimental libraries) Controls interrupt handling, such as alert views, and is compatible with UIKit and Swift UI.

UIPresentCoordinator Controls interrupt handling, such as alert views, and is compatible with UIKit and Swift UI. This library manages items that are

Jan 22, 2022
Highly customizable alertview and alert/notification/success/error/alarm popup written in Swift
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

Aug 1, 2022
PMAlertController is a great and customizable alert that can substitute UIAlertController
PMAlertController is a great and customizable alert that can substitute UIAlertController

PMAlertController is a small library that allows you to substitute Apple's uncustomizable UIAlertController, with a beautiful and totally customizable

Aug 6, 2022
PMAlertController is a great and customizable alert that can substitute UIAlertController
PMAlertController is a great and customizable alert that can substitute UIAlertController

PMAlertController is a small library that allows you to substitute Apple's uncustomizable UIAlertController, with a beautiful and totally customizable

Aug 6, 2022
Customizable simple Alert and simple ActionSheet for Swift
Customizable simple Alert and simple ActionSheet for Swift

SimpleAlert It is simple and easily customizable alert. Can be used as UIAlertController. Appetize's Demo Requirements Swift 5.0 iOS 9.0 or later How

Jun 23, 2022
BPStatusBarAlert is a library that allows you to easily make text-based alert that appear on the status bar and below navigation bar.
BPStatusBarAlert is a library that allows you to easily make text-based alert that appear on the status bar and below navigation bar.

BPStatusBarAlert BPStatusBarAlert is a library that allows you to easily make text-based alert that appear on the status bar and below navigation bar.

Dec 22, 2021
A simple alert with logo image and color.
A simple alert with logo image and color.

YMLogoAlert About YMLogoAlert A simple custom alert. YMLogoAlert lets you pop up a simple alert with a natural animation, your app's own color, font a

Jul 29, 2022
TextFieldAlert - A SwiftUI alert with text field(s) for iOS 13 and greater.
TextFieldAlert - A SwiftUI alert with text field(s) for iOS 13 and greater.

TextFieldAlert A SwiftUI alert with text field(s) for iOS 13 and greater. As Apple is going to introduce text field(s) as an alert actions in iOS 16,

Jul 10, 2022
An easier constructor for UIAlertController. Present an alert from anywhere.
An easier constructor for UIAlertController. Present an alert from anywhere.

ALRT An easier constructor for UIAlertController. Present an alert from anywhere like this. ALRT.create(.alert, title: "Alert?").addOK().addCancel().s

Feb 4, 2022
A colored alert view for your iOS.
A colored alert view for your iOS.

日本語 KRAlertController KRAlertController is a beautiful and easy-to-use alert controller for your iOS written by Swift. Requirements iOS 10.0+ Xcode 10

Jun 30, 2022
A simple, customizable popup dialog for iOS written in Swift. Replaces UIAlertController alert style.
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

Aug 1, 2022
Beautiful animated Alert View. Written in Swift
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

Aug 7, 2022
Live animated Alert View for iOS written in Swift
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

Aug 9, 2022
Zingle – An alert will display underneath your UINavigationBar 🎅
Zingle – An alert will display underneath your UINavigationBar 🎅

Zingle Zingle – An alert will display underneath your UINavigationBar ?? ?? Note: Zingle has a dependency to have a UINavigationController in your app

Jun 24, 2022