HWToast 0.9

HWToast 0.9

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布最新发布2015 年 9 月

CallMeWhy 维护。



  • callmewhy

什么是

HWToast 可以以灵活的方式显示带有自定义视图的 toast。

如何使用

HWToastMaker

您可以使用 maker 来轻松地创建 toast。

[HWToast showToastWithMaker:^(HWToastMaker *maker) {
    // Superview of the toast. If the baseView is nil, the toast will be added to a new window over the screen.
    maker.baseView = nil;

    // The toast view. It could be a text toast(HWTextToastView) 、 a loading toast(HWLoadingToastView) or other HWToastView.
    maker.contentView = [[HWTextToastView alloc] initWithText:text];

    // The toast will disappear after duration. Default value is 0 and it will be on the screen permanently.
    maker.duration = 0.2f;

    // Should it be dismissed on taped. Default is NO.
    maker.shouldDismissOnTaped = YES;

    // Whether the dismiss will be animated.
    maker.dismissAnimated = YES;

    // The callback will be called after the toast been taped.
    maker.tapCallback = ^(UIView *view){
        NSLog(@"You touched me!");
    };

    // The toast's position according to baseView
    maker.position = HWToastPositionBottom;

    // The offset relative to the position.
    maker.offsset = UIOffsetMake(0, -100);
}];

您还可以将 maker 块抽象为类方法

@implementation HWToastTool

+(void)showToastWithText:(NSString*)text {
    [HWToast showToastWithMaker:^(HWToastMaker *maker) {
        maker.contentView = [[HWTextToastView alloc] initWithText:text];
        maker.duration = 2.0f;
    }];
}

@end

并像这样调用它

[HWToastTool showToastWithText:@"Hi, I'm a toast from HWToastTool!"];

HWToastView

您可以创建继承自 HWToastView 的自定义 toast 视图。

就像 HWTextToastViewHWLoadingToastViewHWPieChartToastView 一样。