vgno / MessageBarManager

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MessageBarManager

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

Requirements

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

Author

Terry Worona

Tweet me @terryworona

Email me at terryworona@gmail.com

Installation

CocoaPods is the recommended method of installing the MessageBarManager.

The Pod Way

Simply add the following line to your Podfile:

pod 'MessageBarManager'

Your podfile should look something like:

platform :ios, '6.1'
pod 'JBChartView', '~> 1.1.0'

The Old School Way

The simpliest way to use MessageBarManager 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. "MessageBarManager").

Usage

Calling the manager

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

[MessageBarManager 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:

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

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

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

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:

[[MessageBarManager sharedInstance] showMessageWithTitle:@"Account Updated!"
                                             description:@"Your account was successfully updated."
                                                    type:MessageBarMessageTypeSuccess 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:

[[MessageBarManager sharedInstance] showMessageWithTitle:@"Message 1"
                                             description:@"Description 1"
                                                    type:MessageBarMessageTypeSuccess];

[[MessageBarManager sharedInstance] showMessageWithTitle:@"Message 2"
                                             description:@"Description 2"
                                                    type:MessageBarMessageTypeError];

[[MessageBarManager sharedInstance] showMessageWithTitle:@"Message 3"
                                             description:@"Description 3"
                                                    type:MessageBarMessageTypeInfo];

Customization

The MessageBarStyleSheet has functions pertaining to background and stroke color as well as icon images. All of these functions may be subclassed and/or directly modified to customize the look and feel of the message bar.

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

New Types

Add the new type to the typedef found in MessageBarManager.h.

typedef enum {
	MessageBarMessageTypeError,
    MessageBarMessageTypeSuccess,
	MessageBarMessageTypeInfo,
    MessageBarMessageTypeWarning // new type for warnings
} MessageBarMessageType;

Add new colors and icons to the stylesheet:

+ (UIColor*)backgroundColorForMessageType:(MessageBarMessageType)type
{
	UIColor *backgroundColor = nil;
    switch (type) {
    
	    …
	
		case MessageBarMessageTypeWarning:
        	backgroundColor = [UIColor grayColor]; // warnings to be gray background
            break;
	    default:
    	    break;
    }
    return backgroundColor;
}

+ (UIColor*)strokeColorForMessageType:(MessageBarMessageType)type
{
	UIColor *strokeColor = nil;
    switch (type) {
    
	    …
	
		case MessageBarMessageTypeWarning:
        	strokeColor = [UIColor darkGrayColor];
            break;
	    default:
    	    break;
    }
    return strokeColor;
}

+ (UIImage*)iconImageForMessageType:(MessageBarMessageType)type
{
    UIImage *iconImage = nil;
	switch (type) {
	
		…
	
        case MessageBarMessageTypeWarning:
	        iconImage = [UIImage imageNamed:@"icon-warning.png"]; // warning icon
    	    break;
        default:
	        break;
	}
	return iconImage;
}

Displaying a new message with the message type:

[[MessageBarManager sharedInstance] showMessageWithTitle:@"Account Warning!"
                                             description:@"Your account has expired!"
                                                    type:MessageBarMessageTypeWarning];

License

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

About

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

License:MIT License


Languages

Language:Objective-C 97.8%Language:Ruby 2.2%