Skip to content

Latest commit

 

History

History
82 lines (61 loc) · 2.59 KB

README.md

File metadata and controls

82 lines (61 loc) · 2.59 KB

DPToastView

(Yet another) Highly customizable toast view for iOS. This toast view supports simple strings or attributed strings, word wrap, notifications, and much more.

Usage

Add the dependency to your Podfile:

platform :ios
pod 'DPToastView'
...

Run pod install to install the dependencies.

Import the header file:

#import "DPToastView.h"

Make some toast!

// Show a simple toast.
DPToastView *toast = [DPToastView makeToast:@"I am just a string."];
[toast show];

or...

// Create an attributed string to display.
NSMutableParagraphStyle *parStyle = [[NSMutableParagraphStyle alloc] init];
[parStyle setAlignment:NSTextAlignmentCenter];
[parStyle setLineBreakMode:NSLineBreakByWordWrapping];

NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"I am an attributed toast that is centered and word wrapped."
                                                                        attributes:@{
                                                   NSForegroundColorAttributeName : [UIColor yellowColor],
                                                    NSUnderlineStyleAttributeName : @(NSUnderlineStyleSingle),
                                                              NSFontAttributeName : [UIFont boldSystemFontOfSize:24.0],
                                                    NSParagraphStyleAttributeName : parStyle
                                  }];
DPToastView *toast = [DPToastView makeToast:str];
[toast show];

Add some default styling with a category:

// Category on UIViewController...
@interface UIViewController (CustomDPToast)
- (id)makeRedToast:(NSString *)message gravity:(DPToastGravity)gravity duration:(NSTimeInterval)duration;
@end

@implementation UIViewController (CustomDPToast)
- (id)makeRedToast:(NSString *)message gravity:(DPToastGravity)gravity duration:(NSTimeInterval)duration {
    DPToastView *toastView = [DPToastView makeToast:message gravity:gravity duration:duration];
    // Style the toast...
    [toastView setBackgroundColor:[[UIColor redColor] colorWithAlphaComponent:0.8]];
    [toastView setFont:[UIFont boldSystemFontOfSize:20.0]];
    return toastView;
}
@end

// and finally in your view controller...
DPToastView *toast = [self makeRedToast:@"I am a red toast" gravity:DPToastGravityCenter duration:DPToastDurationNormal];
[toast show];

Requirements

DPToastView requires iOS 6.x or greater. Requires ARC and auto-layout.

License

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