MBProgressHUD自定义视图不会出现

时间:2013-07-21 07:56:58

标签: ios objective-c mbprogresshud

我正在尝试使用此代码在MBProgressHUD上显示图像

MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];
HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark"]] autorelease];
HUD.mode = MBProgressHUDModeCustomView;
HUD.labelText = @"تم إرسال وزنك بنجاح";

[HUD show:YES];
[HUD hide:YES afterDelay:1.5];

但这就是我得到的

enter image description here

问题是什么?

4 个答案:

答案 0 :(得分:2)

我尝试了你的代码,它对我有用。

在MBProgressHud.h文件中,在注释中提到了

/**
 * The UIView (i.g., a UIIMageView) to be shown when the HUD is in MBProgressHUDModeCustomView.
 * For best results use a 37 by 37 pixel view (so the bounds match the build in indicator bounds). 
 */

因此,您使用的图像可能缺失或未包含在内。请检查一下。

答案 1 :(得分:0)

您必须在xcode项目中包含来自this link的图片,好像您没有这样做。

答案 2 :(得分:0)

那是因为您的项目中没有名为“ 37x-Checkmark ”的图像。只需在项目中添加37x-Checkmark.png图像文件即可。

答案 3 :(得分:0)

Now it is changed with IOS &

-(IBAction)save:(id)sender
{
        HUD = [[MBProgressHUD alloc] initWithWindow:[[UIApplication sharedApplication] keyWindow]];
        [[[UIApplication sharedApplication] keyWindow] addSubview:HUD];

        HUD.delegate = self;
        HUD.labelText = @"Initiating Entropy...";
        HUD.minSize = CGSizeMake(135.f, 135.f);
        [HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES];
}

-(void)myTask
{
    sleep(6);
    UIView *v = [[UIView alloc] init];
    UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"check_mark_green"]];
    [v setFrame:CGRectMake(0, 0, img.frame.size.width, img.frame.size.height)];
    v.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"37x-Checkmark"]];

    HUD.mode = MBProgressHUDModeCustomView;
    HUD.customView = v;
    HUD.labelText = nil;
    HUD.detailsLabelText = @"Geo-Location Cordinates Secured";
 }

试试这个并享受代码。