A modern iOS toast view that can fit your notification needs

Overview

CRToast

Build Status Pod Version Carthage compatible

CRToast is a library that allows you to easily create notifications that appear on top of or by pushing out the status bar or navigation bar. CRToast was originally based on CWStatusBarNotification.

demo

Requirements

CRToast uses ARC and requires iOS 7.0+. Works for iPhone and iPad.

Installation

CocoaPods

pod 'CRToast', '~> 0.0.7'

Carthage

github "cruffenach/CRToast"

Manual

Add the project or source files to your own project.

Usage

Notifications can be created through CRToastManager's showNotificationWithOptions:completionBlock: This will queue up a notification with the options specified. You provide options for your notification in a dictionary using the keys in CRToast.h

Example

This code

NSDictionary *options = @{
                          kCRToastTextKey : @"Hello World!",
                          kCRToastTextAlignmentKey : @(NSTextAlignmentCenter),
                          kCRToastBackgroundColorKey : [UIColor redColor],
                          kCRToastAnimationInTypeKey : @(CRToastAnimationTypeGravity),
                          kCRToastAnimationOutTypeKey : @(CRToastAnimationTypeGravity),
                          kCRToastAnimationInDirectionKey : @(CRToastAnimationDirectionLeft),
                          kCRToastAnimationOutDirectionKey : @(CRToastAnimationDirectionRight)
                          };
[CRToastManager showNotificationWithOptions:options
                            completionBlock:^{
                                NSLog(@"Completed");
                            }];

Generates this

Customization

CRToast is very customizable. Taking a hint from UIStringDrawing's drawInRect:withAttributes: book, notifications are created with dictionaries filled with all their options.

Customizing Appearance

CRToast allows for setting of

  • Left aligned image

Title and Subtitle text with:

  • Text Color
  • Text Font
  • Text Alignment
  • Text Color
  • Text Shadow Color
  • Text Shadow Offset
  • Text Max Number of Lines

Customizing Animation

CRToast also allows for animation customization. This includes.

  • Animation Type (Linear, Spring or Gravity)
  • Animation Physics Coefficients (Spring Damping, Spring Initial Velocity, Gravity Magnitude)
  • Presentation Type (Slide over bars or push content out)
  • Status visibility (Status bar on top or below)
  • Direction (Enter and exit in any direction)
  • Enter, Stay on Screen and Exit Timing

Touch Interactions

CRToast allows for any notification to respond to different types of touch interactions (tap, swipe). Interaction responders can be set as defaults or on a per notification basis. The types of interactions you can set up to respond to are:

CRToastInteractionTypeSwipeUp
CRToastInteractionTypeSwipeLeft
CRToastInteractionTypeSwipeDown
CRToastInteractionTypeSwipeRight
CRToastInteractionTypeTapOnce
CRToastInteractionTypeTapTwice
CRToastInteractionTypeTwoFingerTapOnce
CRToastInteractionTypeTwoFingerTapTwice

There are also wild card interaction types which cover a range of interactions

CRToastInteractionTypeSwipe
CRToastInteractionTypeTap
CRToastInteractionTypeAll

Any interaction can be responded to using a CRToastInteractionResponder, they can be made with the following constructor

+ (instancetype)interactionResponderWithInteractionType:(CRToastInteractionType)interactionType
                                   automaticallyDismiss:(BOOL)automaticallyDismiss
                                                  block:(void (^)(CRToastInteractionType interactionType))block;

You can set a collection of CRToastInteractionResponders as the object for the key kCRToastInteractionRespondersKey in defaults to have all notifications respond to a certain interaction, or on any given one to have the interaction responders just work for that one notification.

Persistent and Programmatically Dismissed Notifications

You can also dismiss the current notification at any time with

+ (void)dismissNotification:(BOOL)animated;

You can present notifications that must be dismissed by the user by passing @(DBL_MAX) for kCRToastTimeIntervalKey and setting up an interaction responder that will dismiss the notification.

Setting Defaults

There are sane defaults set for all properties, however you can set a default set of options for your application's notifications using CRToastManagers's setDefaultOptions:.

License

The MIT License (MIT)

Copyright (c) 2013 Collin Ruffenach

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Comments
  • Complete Refactor

    Complete Refactor

    This is a complete reorganization of the current file structure. In the process I had to make a few more things 'public' since all the implementations were in one file allowing for shared knowledge.

    I don't know if this is something you're looking to do, however I would like to start the discussion about it. This PR supersedes all my other pull (https://github.com/cruffenach/CRToast/pull/122, https://github.com/cruffenach/CRToast/pull/121, https://github.com/cruffenach/CRToast/pull/120, https://github.com/cruffenach/CRToast/pull/115) requests as well as adds a few other features from other users that have mentioned changed in the issues (https://github.com/miwillhite/CRToast/commit/498a731fb818c3aa7e2e5cf2b6a5bb56c8befc9f, https://github.com/cruffenach/CRToast/pull/69). I'm not 100% sure the changes in https://github.com/cruffenach/CRToast/pull/69 are successful & still pass but thats another issue.

    Is this something that you would like to do? I feel that it adds a few requested features as well as fixes a few bugs. Maybe not in the same way but I tried to stay consistent to the current codebase. issues with the current code format have been brought up so i felt that refactoring was a decent idea even if it does come at a slight loss of elegance.

    This is a gargantuan PR to look over so I totally understand not being super stoked about seeing it :grin: sorry.

    opened by dmiedema 13
  • NSInternalInconsistencyException

    NSInternalInconsistencyException

    I am calling CRToast from UIViewcontroller with below code;

    (void) userParamsSaved { NSDictionary *options = @{ kCRToastTextKey : @"Hello World!", kCRToastTextAlignmentKey : @(NSTextAlignmentCenter), kCRToastBackgroundColorKey : [UIColor redColor], kCRToastAnimationInTypeKey : @(CRToastAnimationTypeGravity), kCRToastAnimationOutTypeKey : @(CRToastAnimationTypeGravity), kCRToastAnimationInDirectionKey : @(CRToastAnimationDirectionLeft), kCRToastAnimationOutDirectionKey : @(CRToastAnimationDirectionRight) }; [CRToastManager showNotificationWithOptions:options completionBlock:^{}];

    } and get

    *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid size {320, 0} for item <CRToastView: 0x1093935f0; frame = (-320 0; 320 0); userInteractionEnabled = NO; layer = <CALayer: 0x10932fd70>> in Dynamics'

    what i am missing?

    bug 
    opened by ghost 13
  • Don't redisplay toast that is already showing

    Don't redisplay toast that is already showing

    I needed the following hack in order to prevent the same toast message from being displayed over and over.

    id manager = [CRToastManager valueForKeyPath:@"manager"];
    id notification = [manager valueForKeyPath:@"notification"];
    NSString *existingTitle = [notification valueForKeyPath:@"text"];
    NSString *existingSubtitle = [notification valueForKeyPath:@"subtitleText"];
    if ([existingTitle isEqualToString:title] && [existingSubtitle isEqualToString:message]) {
        return;
    }
    

    The problem is that if the same message is displayed often, it keeps animating away and back again. I would prefer that it is ignored or that the old toast is replaced without animation.

    Is there a better way of achieving my goal?

    opened by onato 12
  • Add new 'appearance' optional block, constructors to enable proper syncing of sound/vibration with queued notifications.

    Add new 'appearance' optional block, constructors to enable proper syncing of sound/vibration with queued notifications.

    CRToast automatically handles notification queuing, which is great -- it's essentially fire-and-forget. Currently, there is an optional block that you can provide to be called after a notification shows. Unfortunately, there isn't a way to get notified when a notification is actually being shown.

    The scenario here is that several notifications are queued to show, and you want to play a sound / vibration each time a notification is dequeued/shown.

    This change simply adds an additional block property to CRToast, and a new constructor that lets the caller provide it. The block is called immediately before the notification is shown.

    I did my best to emulate the project formatting / conventions -- if you have feedback, I'm happy to do an iteration or two. Thanks for providing this library -- it's really great.

    Thanks,

    Andy

    opened by andyzei 11
  • Autorotate

    Autorotate

    This PR enables the ability to set an autorotate flag. This was useful for me to require all toasts to come in through portrait, formerly when a toast came in rotating the device would rotate the status bar.

    opened by cruffenach 9
  • Status Bar getting cut off

    Status Bar getting cut off

    I'm getting the Status Bar showing up all weird. screen shot 2014-04-30 at 8 35 13 pm I'm just using the regular code in viewWillAppear... any ideas? NSDictionary *options = @{ kCRToastTextKey : [NSString stringWithFormat:@"Hello World!"], kCRToastTextAlignmentKey : @(NSTextAlignmentCenter), kCRToastBackgroundColorKey : [UIColor blueColor], kCRToastAnimationInTypeKey : @(CRToastAnimationTypeGravity), kCRToastAnimationOutTypeKey : @(CRToastAnimationTypeGravity), kCRToastAnimationInDirectionKey : @(CRToastAnimationDirectionLeft), kCRToastAnimationOutDirectionKey : @(CRToastAnimationDirectionRight) }; [CRToastManager showNotificationWithOptions:options completionBlock:^{ NSLog(@"Completed"); }];

    bug 
    opened by reez 8
  • Add support for iOS 7 light status bar

    Add support for iOS 7 light status bar

    When using a white status bar, the text goes black right before the notifications show until right after they disappear and then flashes back to white.

    opened by MrMatthewDavis 8
  • Memory Leak

    Memory Leak

    Hello,

    We've been noticing a pretty large memory leak that causes our app to crash pretty often when a number of these are shown during a session user session. We have an app that shows roughly 80-100 of these in a single session and probably stressing it quite a bit. We've seen that this eventually causes the device to hard reset due to either memory leaking or excessive page allocation. We see that roughly 4-8MB are allocated and freed when a notification is shown from the top.

    We've profiled this in Instruments and aren't able to catch much because it seems to be rather elusive. We've pulled the library and replaced with a our own and all crashes have stopped.

    Here's our usage that resulted in the memory leaks:

    `// // POTPopupManager.m // Potion // // Created by Gabe Brown on 10/15/15. // Copyright © 2015 Potion Incorporated. All rights reserved. //

    import "POTPopupManager.h"

    import "CRToast.h"

    @implementation POTPopupManager

    @synthesize staticOptions;

    /**

    • Class initializer
    • @return Instance of POTPopupManager */ +(NSMutableDictionary *)getOptions {

    NSDictionary *staticOptions = @{ kCRToastNotificationTypeKey: @(CRToastTypeNavigationBar), kCRToastNotificationPresentationTypeKey: @(CRToastPresentationTypeCover), kCRToastTextAlignmentKey : @(NSTextAlignmentCenter), kCRToastBackgroundColorKey : [UIColor orangeColor], kCRToastAnimationInTypeKey : @(CRToastAnimationTypeSpring), kCRToastAnimationOutTypeKey : @(CRToastAnimationTypeGravity), kCRToastAnimationInDirectionKey : @(CRToastAnimationDirectionBottom), kCRToastAnimationOutDirectionKey : @(CRToastAnimationDirectionTop), kCRToastNotificationPresentationTypeKey: @(CRToastPresentationTypeCover), kCRToastTimeIntervalKey: @(3.0), kCRToastInteractionRespondersKey: @[ [CRToastInteractionResponder interactionResponderWithInteractionType:CRToastInteractionTypeTapOnce automaticallyDismiss:YES block:^(CRToastInteractionType interactionType) { // DO NOTHING } ], [CRToastInteractionResponder interactionResponderWithInteractionType:CRToastInteractionTypeSwipe automaticallyDismiss:YES block:^(CRToastInteractionType interactionType) { // DO NOTHING } ] ] };

    NSMutableDictionary *options = [[NSMutableDictionary alloc] initWithDictionary:staticOptions];

    return options;

    }

    /**

    • Shows the popup on the main thread and calls the callback / +(void)showPopupWithCompletion:(void (^)(void))completion options:(NSMutableDictionary)options {

    dispatch_async(dispatch_get_main_queue(), ^{

    [CRToastManager showNotificationWithOptions:options
                                completionBlock:^{
                                    if(completion) {
                                        completion();
                                    }
                                }];
    

    });

    }

    /**

    • Shows an success popup on the main thread
    • @param message The message to display
    • @param completion Method called when completed */

    +(void)showSuccessPopupWithMessage:(NSString*)message completion:(void (^)(void))completion {

    NSMutableDictionary *options = [POTPopupManager getOptions];
    
    [CRToastManager dismissAllNotifications:YES];
    options[kCRToastTextKey] = message;
    options[kCRToastBackgroundColorKey] = [UIColor colorWithRed:0.20 green:0.69 blue:0.20 alpha:1.0];
    options[kCRToastTextColorKey] = [UIColor whiteColor];
    [POTPopupManager showPopupWithCompletion:completion options:options];
    

    }

    /**

    • Shows an info popup on the main thread
    • @param message The message to display
    • @param completion Method called when completed / +(void)showInfoPopupWithMessage:(NSString)message completion:(void (^)(void))completion {

    NSMutableDictionary *options = [POTPopupManager getOptions];

    [CRToastManager dismissAllNotifications:NO]; options[kCRToastTextKey] = message; options[kCRToastBackgroundColorKey] = [UIColor blackColor]; options[kCRToastTextColorKey] = [UIColor whiteColor]; [POTPopupManager showPopupWithCompletion:completion options:options]; }

    /**

    • Shows an info popup on the main thread
    • @param message The message to display
    • @param completion Method called when completed / +(void)showInfoPopupWithMessage:(NSString)message completion:(void (^)(void))completion duration:(float)duration {

    NSMutableDictionary *options = [POTPopupManager getOptions];

    [CRToastManager dismissAllNotifications:NO]; options[kCRToastTextKey] = message; options[kCRToastBackgroundColorKey] = [UIColor blackColor]; options[kCRToastTextColorKey] = [UIColor whiteColor]; options[kCRToastTimeIntervalKey] = @(duration);

    [POTPopupManager showPopupWithCompletion:completion options:options];

    }

    /**

    • Shows an warning popup on the main thread
    • @param message The message to display
    • @param completion Method called when completed */

    +(void)showWarningPopupWithMessage:(NSString*)message completion:(void (^)(void))completion {

    NSMutableDictionary *options = [POTPopupManager getOptions];
    
    [CRToastManager dismissAllNotifications:NO];
    options[kCRToastTextKey] = message;
    options[kCRToastBackgroundColorKey] = [UIColor colorWithRed:0.59 green:0.04 blue:0.04 alpha:1.0];
    options[kCRToastTextColorKey] = [UIColor whiteColor];
    [POTPopupManager showPopupWithCompletion:completion options:options];
    

    }

    /**

    • Shows an info popup on the main thread
    • @param message The message to display
    • @param completion Method called when completed / +(void)showErrorPopupWithMessage:(NSString)message completion:(void (^)(void))completion {

    NSMutableDictionary *options = [POTPopupManager getOptions];

    [CRToastManager dismissAllNotifications:NO]; options[kCRToastTextKey] = message; options[kCRToastBackgroundColorKey] = [UIColor colorWithRed:0.59 green:0.04 blue:0.04 alpha:1.0]; options[kCRToastTextColorKey] = [UIColor whiteColor]; [POTPopupManager showPopupWithCompletion:completion options:options];

    }

    @end`

    opened by gabosgab 7
  • Fix alignment for when multiple items are centered

    Fix alignment for when multiple items are centered

    This accounts for an 'edge' case where we have centered text & a centered accessory view. To account for this we move the accessory off to the left side so that the text can remain centered while not covering it up with said accessory view.

    This may not be the prettiest solution so I'm open to suggestions if anyone has them.

    Took screen shots of the results ios simulator screen shot aug 1 2015 4 36 59 pm ios simulator screen shot aug 1 2015 4 37 06 pm

    cc @nmock, @jadar

    opened by dmiedema 7
  • Enhancement --- It will be great to have toast at bottom of screen or below the navigation bar

    Enhancement --- It will be great to have toast at bottom of screen or below the navigation bar

    It will be great to have toast at bottom of screen like android snackbar or below the navigation bar like crouton library in android to avoid app rejection of covering the status bar...Thanks

    opened by hardikamal 7
  • APP will be reject because it blocks status bar.

    APP will be reject because it blocks status bar.

    I've been reject twice because of following reason:

    After further review, we notice that your app does not comply with the Apple iOS Human Interface Guidelines. 
    
    Specifically, we noticed that your app provides an overlay that partially or totally blocks the status bar.
    

    So, using it carefully.

    opened by ch8908 7
  • Solved: Subtitle text not showing

    Solved: Subtitle text not showing

    Testing to try to get subtitles in the notification, but it simple will not appear. The following is my options array:

    var options:[String:Any] = [kCRToastTextKey: "Morgan: ", kCRToastBackgroundColorKey: UIColor.herGrey, kCRToastTextColorKey: UIColor.herBlack, kCRToastNotificationTypeKey: NSNumber(value: CRToastType.navigationBar.rawValue), kCRToastFontKey: UIFont.herMediumFont(ofSize:16), kCRToastTextAlignmentKey:NSNumber(value: NSTextAlignment.left.rawValue),kCRToastSubtitleTextAlignmentKey: NSNumber(value: NSTextAlignment.left.rawValue), kCRToastSubtitleTextKey: "Hey girl heyyyy", kCRToastSubtitleFontKey: UIFont.herLightFont(ofSize:16), kCRToastSubtitleTextMaxNumberOfLinesKey: 1]

    Here is what I see: screen shot 2018-07-16 at 10 25 50 am

    This is on iPhone 8 Plus, iOS 11.4.

    Is it possible I am missing something ?

    opened by mmdock 0
  • Space between title and subtitle when subtitle is long

    Space between title and subtitle when subtitle is long

    I use a toast with icon, title and subtitle. I only want the subtitle to be one line, so setting kCRToastSubtitleTextMaxNumberOfLinesKey to 1.

    When the subtitle is some short text, it works fine

    image

    but with a longer subtitle there is a strange space between the title and the subtitle

    image

    I guess a sizeToFit call is missing somewhere.

    opened by igorkulman 0
Owner
Collin Ruffenach
Collin Ruffenach
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
Bulletin / 'Toast' style view for tvOS.

KBBulletinView Bulletin / 'Toast' style view for tvOS. This project is an effort to create local application notifications/alerts similar to those use

Kevin Bradley 4 Nov 26, 2022
CoffeeToast - A swift package to easily add Toast notifications to your app

CoffeeToast A simple Swift package to add Toast Notifications to your app. Insta

Maegan Wilson 2 Feb 3, 2022
A Simple Toast Library for iOS

PowerplayToastKit Toasts Type Success. Warning Error Info Custom View (Dialog) Example To run the example project, clone the repo, and run pod install

Mithilesh Parmar 18 Jul 2, 2022
A Swift extension that adds toast notifications to the UIView object class.

Toast-Swift Toast-Swift is a Swift extension that adds toast notifications to the UIView object class. It is intended to be simple, lightweight, and e

Charles Scalesse 3.3k Dec 22, 2022
🍞 Toast for Swift

Toaster Android-like toast with very simple interface. (formerly JLToast) Screenshots Features Queueing: Centralized toast center manages the toast qu

Suyeol Jeon 1.6k Dec 30, 2022
LCToast - Add toast to UIView.

LCToast Add toast to UIView. Requirements iOS 8.0+ Features The LCToast is a comparison of features with Toast and SVProgressHUD. LCToast Toast SVProg

LiuChang 158 Nov 22, 2022
Emulates the native Remote Notification View.

Introduction HDNotificationView appears notification view like system. Requirement iOS 9.0+ Installation Carthage github "nhdang103/HDNotificationView

Nguyen Hai Dang 357 Nov 20, 2022
OEANotification is a customizable notification view framework

OEANotification OEANotification is an iOS library which provides to create notifications and customize them easily. You can create notifications with

Ömer Aslan 19 Jan 30, 2021
A simple and attractive AlertView to ask permission to your users for Push Notification.

A simple and attractive AlertView **to ask permission to your users for Push Notification.** PRESENTATION Ask permission to user for push notification

Boisney Philippe 37 Mar 23, 2022
The easiest way to display highly customizable in app notification banners in iOS

Written in Swift 5 NotificationBanner is an extremely customizable and lightweight library that makes the task of displaying in app notification banne

Dalton Hinterscher 4.5k Jan 9, 2023
A lightweight dropdown notification for iOS 7+, in Swift.

BRYXBanner A lightweight dropdown banner for iOS 7+. Usage Import BRYXBanner import BRYXBanner Create a banner using the designated initializer. let b

Bryx, Inc 1k Nov 20, 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
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
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
In-app notification in Swift, with customizable buttons and input text field.

Notie Undistracted in-app notification in Swift, with added buttons and input box. Installation CocoaPods To integrate Notie into your Xcode project u

Thi Doãn 85 Aug 8, 2020
Swifty, modern UIAlertController wrapper.

Alertift Alertift.alert(title: "Alertift", message: "Alertift is swifty, modern, and awesome UIAlertController wrapper.") .action(.default("❤️"))

Suguru Kishimoto 287 Jan 7, 2023
SwiftEntryKit is a presentation library for iOS. It can be used to easily display overlays within your iOS apps.

SwiftEntryKit ?? Donations can be made here. Table of Contents Overview Features Example Project Example Project Installation Presets Playground Requi

Daniel Huri 6.1k Jan 4, 2023
Simple Alert View written in Swift, which can be used as a UIAlertController. (AlertController/AlertView/ActionSheet)

DOAlertController Simple Alert View written in Swift, which can be used as a UIAlertController replacement. It supports from iOS7! It is simple and ea

Daiki Okumura 406 Sep 5, 2022