Code Monkey home page Code Monkey logo

twmessagebarmanager's Introduction

TWMessageBarManager

An iOS manager for presenting system-wide notifications via a dropdown message bar.

Requirements

  • Requires iOS 6.0 or later
  • Requires Automatic Reference Counting (ARC)

Features

  • Drop-in singleton manager supported across all devices.
  • Simple to use protocols and callbacks.
  • Landscape and portrait orientation support.
  • Highly customizable.

Refer to the <a href="https://github.com/terryworona/TWMessageBarManager/blob/master/CHANGELOG.md"">changelog for an overview of TWMessagBarManager's feature history.

Author

Terry Worona

Tweet me @terryworona

Email me at [email protected]

Installation

CocoaPods is the recommended method of installing the TWMessageBarManager.

The Pod Way

Simply add the following line to your Podfile:

pod 'TWMessageBarManager'

Your podfile should look something like:

platform :ios, '6.0'
pod 'TWMessageBarManager', '~> 1.6.0'

The Old School Way

The simpliest way to use TWMessageBarManager with your application is to drag and drop the /Classes folder into you're Xcode 5 project. It's also recommended you rename the /Classes folder to something more descriptive (ie. "TWMessageBarManager").

Usage

Calling the manager

As a singleton class, the manager can be accessed from anywhere within your app via the + sharedInstance function:

[TWMessageBarManager sharedInstance]

Presenting a basic message

All messages can be preseted via showMessageWithTitle:description:type:. Additional arguments include duration and callback blocks to be notified of a user tap.

Basic message:

[[TWMessageBarManager sharedInstance] showMessageWithTitle:@"Account Updated!"
                                               description:@"Your account was successfully updated."
                                                      type:TWMessageBarMessageTypeSuccess];

The default display duration is 3 seconds. You can override this value by supplying an additional argument:

[[TWMessageBarManager sharedInstance] showMessageWithTitle:@"Account Updated!"
                                               description:@"Your account was successfully updated."
                                                      type:TWMessageBarMessageTypeSuccess
                                               forDuration:6.0];

Hiding messages

It's not currently possible to hide or cancel a message on a per-instance basis. Instead, all messages must be canceled at once. This action may or may not be animated:

[[TWMessageBarManager sharedInstance] hideAllAnimated:YES]; // animated

[[TWMessageBarManager sharedInstance] hideAll]; // non-animated

Callbacks

By default, if a user taps on a message while it is presented, it will automatically dismiss. To be notified of the touch, simply supply a callback block:

[[TWMessageBarManager sharedInstance] showMessageWithTitle:@"Account Updated!"
                                               description:@"Your account was successfully updated."
                                                      type:TWMessageBarMessageTypeSuccess callback:^{
                                                          NSLog(@"Message bar tapped!");
}];

Queue

The manager is backed by a queue that can handle an infinite number of sequential requests. You can stack as many messages you want on the stack and they will be presetented one after another:

[[TWMessageBarManager sharedInstance] showMessageWithTitle:@"Message 1"
                                               description:@"Description 1"
                                                      type:TWMessageBarMessageTypeSuccess];

[[TWMessageBarManager sharedInstance] showMessageWithTitle:@"Message 2"
                                               description:@"Description 2"
                                                      type:TWMessageBarMessageTypeError];

[[TWMessageBarManager sharedInstance] showMessageWithTitle:@"Message 3"
                                               description:@"Description 3"
                                                      type:TWMessageBarMessageTypeInfo];

UIStatusBarStyle

The manager utilizes a custom UIWindow & UIViewController to manage orientation. For targets >= iOS7, if a UIStatusBarStyle other than UIStatusBarStyleDefault is desired, simply call:

- (void)showMessageWithTitle:(NSString *)title description:(NSString *)description type:(TWMessageBarMessageType)type statusBarStyle:(UIStatusBarStyle)statusBarStyle callback:(void (^)())callback;

If a message is presented with a custom UIStatusBarStyle, after dismissal, the status bar will revert back to the the system style (that of the current UIVIewController).

If you wish to hide the status bar altogether during presentations, you can do so via:

- (void)showMessageWithTitle:(NSString *)title description:(NSString *)description type:(TWMessageBarMessageType)type statusBarHidden:(BOOL)statusBarHidden callback:(void (^)())callback;

Customization

An object conforming to the TWMessageBarStyleSheet protocol defines the message bar's look and feel:

+ (UIColor *)backgroundColorForMessageType:(TWMessageBarMessageType)type;
+ (UIColor *)strokeColorForMessageType:(TWMessageBarMessageType)type;
+ (UIImage *)iconImageForMessageType:(TWMessageBarMessageType)type;

If no style sheet is supplied, a default class is provided on initialization. To customize the look and feel of your message bars, simply supply an object conforming to the TWMessageBarStyleSheet protocol via:

@property (nonatomic, weak) id<TWMessageBarStyleSheet> styleSheet;

See TWAppDelegateDemoStyleSheet for an example on how to create a custom stylesheet.

License

Usage is provided under the MIT License. See LICENSE for full details.

twmessagebarmanager's People

Contributors

terryworona avatar danielkrofchick avatar pearapps avatar lukaswelte avatar amyworrall avatar grantjk avatar leandros avatar

Watchers

william avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.