在Mac OS中使用MBProgressHUD显示吐司消息

时间:2019-04-30 06:06:43

标签: ios objective-c macos mbprogresshud

我正在使用MBProgressHUD显示吐司消息,但吐司消息得到了一些视图下面是代码正在使用

HUD image

MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:window.contentView animated:YES];;

// Configure for text only and offset down
hud.mode = MBProgressHUDModeText;
hud.labelText = @"some message......";
hud.margin = 10.f;
hud.yOffset = 200.f;
hud.removeFromSuperViewOnHide = YES;
[hud hide:YES afterDelay:20];

3 个答案:

答案 0 :(得分:0)

//只需替换您的代码并检查

AppDelegate *appDel = (AppDelegate *)[[UIApplication sharedApplication] delegate];

MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:appDel.window animated:YES];

答案 1 :(得分:0)

代码:

- (void)showLoader:(NSString*)strTitle view:(UIView*)view
{
    dispatch_async(dispatch_get_main_queue() , ^{
        MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:view.window];
        [view.window addSubview:hud];
        hud.labelText = strTitle;
        [hud show:YES];
    });
}

像这样使用:

[self showLoader:@"Loading.." view:self.view]

答案 2 :(得分:0)

对于macOS,使用MBProgressHud可以这样显示

MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:window.contentView];
            hud.mode = MBProgressHUDModeText;
            hud.labelFont = [NSFont systemFontOfSize:13.0];
            hud.margin = 8.f;
            hud.opacity = 0.7;
            hud.yOffset = NSHeight(window.frame)/2-60;
            hud.cornerRadius = 4.0;
            hud.removeFromSuperViewOnHide = YES;
            hud.detailsLabelText = @"some message......";
            [window.contentView addSubview:hud];
            [hud show:YES];
            [hud hide:YES afterDelay:2.0];