Coder Social home page Coder Social logo

dptoastview's Introduction

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.

dptoastview's People

Contributors

duneparksoftware avatar ebaker355 avatar ericb0774 avatar sixmen avatar

Watchers

Jack avatar  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.