2013-07-21 175 views
6

我试图表现出对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

是什么问题?

+1

我想你的代码,它是为我工作。它只是我用self.view作为HUD的超级视图。确保你下载了正确的图像。它应该是37×37个像素 –

+0

你只需要把巴纽在[UIImage的ImageNamed],它不知道文件扩展名是什么,此刻所以它只会丢什么......牛逼 –

+0

[UIImage的imageNamed:]确实与PNG一起使用时不需要文件扩展名。但是,文件扩展名对于其他文件类型是必需的。对于它的价值,imageNamed也会自动缓存,并且如果使用Apple的图形命名约定(如“myfile @ 2x”与“myfile”)命名文件,将为设备屏幕比例/ DPI确定正确的文件。在这两种情况下,即使没有为“imageNamed:”指定,也会采用“png”。 – Woodster

回答

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). 
*/ 

因此,也许你使用的图像丢失或noyt包括在内。请检查。

0

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

+1

其实我有 – OXXY

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"; 
} 

试试这个,并享受代码。