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

Overview

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

Comments
  • Color for icon in SwiftUI

    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!

    enhancement 
    opened by derech1e 14
  • Add new type of alert — Loading Alert

    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?

    opened by mlouli 8
  • Loading View

    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

    opened by PedroCavaleiro 6
  • Alert appears behind keyboard if the keyboard is open.

    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

    enhancement wait more 
    opened by tijme 6
  • Is it possible that we can display things other than images inside the alert?

    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 :)

    enhancement 
    opened by konekoya 3
  • Xcode 13 beta 3: 'shared' is unavailable in application extensions for iOS

    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
    bug 
    opened by gongzhang 3
  • layout.bottomSpace no longer accessible

    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

    bug 
    opened by salvatoreboemia 3
  • is this completion handler or button action possible?

    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

    opened by chetandobariya 2
  • I needed to add a delegate or a completionHandler for when animation is done

    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)
                }
            })
        }
    
    enhancement 
    opened by waelsaad 2
  • Set dismissByTap to false is not working

    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

    bug 
    opened by hstdt 1
  • Add NSAttributedString present

    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
    opened by viktart 1
  • I made this for React Native!

    I made this for React Native!

    Hey! Just wanted to share that I wrapped this library (and SPIndicator) for React Native. I'd never used Swift before.

    You can see it here: https://github.com/nandorojo/burnt

    And I wrote about it here: https://twitter.com/FernandoTheRojo/status/1592923529644625920

    Thanks for the great library!

    bug 
    opened by nandorojo 0
  • Content color is not always correct for Dark Mode.

    Content color is not always correct for Dark Mode.

    Details

    • iOS Version 13+
    • Framework Version 4.2.0
    • Installed via SPM

    Describe the Bug Content color is not always correct for Dark Mode.

    Reason When initiating the view, defaultContentColor is called from the initializer, looking for a window to get the traitCollection. As the window is not defined yet, nil is returned, and lightColor will always be in use.

    Solution for iOS 13+ only Use UIColor.init(dynamicProvider: _)

    I'll make a PR about that. EDIT: opened https://github.com/ivanvorobei/SPAlert/pull/44

    I don't know yet how to fix it for iOS 12.x

    bug 
    opened by Dean151 0
  • Better init for SPAlert with preset only

    Better init for SPAlert with preset only

    Goal

    Preset color was not defined and layout was wrong (top margin > bottom margin, preset not centered).

    Checklist

    • [x] Testing in compability platforms
    • [x] Installed correct via Swift Package Manager and Cocoapods
    opened by relisiuol 0
Releases(4.2.0)
Owner
Ivan Vorobei
iOS Developer
Ivan Vorobei
zekunyan 608 Dec 30, 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
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

Evgenii Neumerzhitckii 874 Dec 13, 2022
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

Evgenii Neumerzhitckii 874 Dec 13, 2022
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

Adonis Peralta 407 Nov 29, 2022
(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

Yuki Tamazawa 1 Jan 22, 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
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

Paolo Musolino 2.5k Jan 3, 2023
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

Paolo Musolino 2.5k Jan 3, 2023
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

Kyohei Ito 397 Dec 6, 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 BPStatusBarAlert is a library that allows you to easily make text-based alert that appear on the status bar and below navigation bar.

Ben.Park 131 Aug 12, 2022
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

Youngminah 8 Dec 21, 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. As Apple is going to introduce text field(s) as an alert actions in iOS 16,

Piotr Sochalewski 13 Dec 5, 2022
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

Masahiro Watanabe 97 Nov 11, 2022
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

K.R.Impedance 52 Jun 30, 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
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

Hemang 109 Jun 24, 2022