DPToastView 0.2.2

DPToastView 0.2.2

测试测试
语言语言 Obj-CObjective C
许可 MIT
发布最后发布2015年3月

Eric Baker 维护。



  • Eric Baker

(另一个)适用于 iOS 的高度可定制的 toast 视图。此 toast 视图支持简单的字符串或富文本字符串、自动换行、通知等。

使用方法

将依赖添加到您的 Podfile

platform :ios
pod 'DPToastView'
...

运行 pod install 以安装依赖项。

导入头文件

#import "DPToastView.h"

做一些 toast!

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

或者...

// 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];

使用类别添加一些默认样式

// 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];

要求

DPToastView 需要 iOS 6.x 或更高版本。需要 ARC 和自动布局。

许可

使用服从MIT 许可。有关详情,请参阅 LICENSE。