HWToast 可以以灵活的方式显示带有自定义视图的 toast。
您可以使用 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 的自定义 toast 视图。
就像 HWTextToastView
、 HWLoadingToastView
和 HWPieChartToastView
一样。