MBProgressHUD custom view doesn't appear - ios

I'm trying to show an image on MBProgressHUD by using this code
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];
but this is what i get
what is the problem ?

I tried your code and it is working for me.
In MBProgressHud.h file, in comments it is mentioned that
/**
* 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).
*/
So perhaps the image you used is missing or is noyt included. Please check that.

You must include the images from this link in your xcode project, seems you didn't do so.

That's because you don't have the image named "37x-Checkmark" in your project. Just add the 37x-Checkmark.png image file in your project.

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";
}
try this and enjoy the code.

Related

in iOS8: UIPopoverController presentPopoverFromRect not work for keyWindow any more

As titled, in iOS8, [UIPopoverController presentPopoverFromRect] does not work for [UIApplication sharedApplication].keyWindow any more. (It does work in iOS7)
I verified following codes:
TestViewController *test = [[TestViewController alloc] initWithNibName:nil bundle:nil];
if (testPopoverController == nil) {
testPopoverController = [[UIPopoverController alloc] initWithContentViewController:test];
testPopoverController.popoverContentSize = CGSizeMake(250, 95*5);
}
CGPoint point = [sender convertPoint:CGPointMake(0, 0) toView:nil];
CGRect rect = CGRectMake(point.x, point.y, 24, 24);
[testPopoverController presentPopoverFromRect:rect inView:[UIApplication sharedApplication].keyWindow permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
The best solution I've come up with is to handle it conditionally. If on iOS 7, use the working code we had for presenting a UIPopoverController on the key window. If on iOS 8, use the following:
viewController.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *presentationController = viewController.popoverPresentationController;
[presentationController setDelegate:self];
presentationController.permittedArrowDirections = 0;
presentationController.sourceView = [[UIApplication sharedApplication] keyWindow];
presentationController.sourceRect = [[UIApplication sharedApplication] keyWindow].bounds;
[viewController setPreferredContentSize:CGSizeMake(320, 480)];
[parentController presentViewController:viewController animated:YES completion:nil];
This ends up functioning identically to:
self.popoverController = [[UIPopoverController alloc] initWithContentViewController:viewController];
[self.popoverController setDelegate:self];
[self.popoverController setPopoverContentSize:isLandscape() ? CGSizeMake(480*2, 320*2) : CGSizeMake(320*2, 480*2)];
[self.padPopover presentPopoverFromRect:CGSizeMake(320, 480)
inView:[[UIApplication sharedApplication] keyWindow]
permittedArrowDirections:0
animated:YES];
Change the inView parameter in
[testPopoverController presentPopoverFromRect:rect inView:[UIApplication sharedApplication].keyWindow permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
to
[testPopoverController presentPopoverFromRect:rect inView:"your current View Controller's view" permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
And make sure it is in dispatch block
dispatch_async(dispatch_get_main_queue(), ^{
});
Also kip changing your rect origin n size values if it is within the bounds
Try the solution found at this link: http://github.com/werner77/WEPopover
1st, let's do this code:
if ([viewController respondsToSelector:#selector(setPreferredContentSize:)]) {
viewController.preferredContentSize = CGSizeMake(200, 300.0f);
} else {
viewController.contentSizeForViewInPopover = CGSizeMake(200.0f, 300.0f);
}
self.popoverController = [[popoverClass alloc] initWithContentViewController:viewController];
if ([self.popoverController respondsToSelector:#selector(setContainerViewProperties:)]) {
[self.popoverController setContainerViewProperties:[self improvedContainerViewProperties]];
}
self.popoverController.delegate = self;
[self.popoverController presentPopoverFromRect:[sender bounds]
inView:sender
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];
I hope this helps. It was tested and works for iOS6-iOS8.
PS. Don't forget to check viewDidLoad, and give thanks to the WEPopover Library.
I think you have to display it in full view/viewcontroller and not in [UIApplication sharedApplication].keyWindow
So change this code:
[testPopoverController presentPopoverFromRect:rect inView:[UIApplication sharedApplication].keyWindow permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
to:
[testPopoverController presentPopoverFromRect:rect inView:aViewControllerInYourApp permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];

How to set frame in center xcode

Im making iPhone app using frame, my frame is not in center and it repeats. I want to set in center and I hate when my frames repeats multiple times.
Im using following code:
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
// picker.delegate = self;
[picker setSourceType:UIImagePickerControllerSourceTypeCamera];
// creating overlayView
UIView* overlayView = [[UIView alloc] initWithFrame:picker.view.frame];
// letting png transparency be
overlayView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"f2.png"]];
[overlayView.layer setOpaque:NO];
overlayView.opaque = NO;
picker.showsCameraControls = NO;
picker.cameraOverlayView = overlayView;
//[self presentModalViewController:picker animated:YES];
[self presentViewController:picker animated:YES completion:nil];
Am I missing something ?
TNX in advance.
I'm not sure, what you are asking, but maybe changing from frame to bounds could solve you problem:
UIView* overlayView = [[UIView alloc] initWithFrame:picker.view.bounds];

MBProgressHUD , crashes many times

I am using this api to share an image , but it crashes many many times !!! my code is runs fine but sometimes MBProgressHUD causes app crashing , am I using this API right ?
- (void)shareOther {
HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];
HUD.delegate = self;
HUD.labelText = #"Loading";
[HUD showWhileExecuting:#selector(capture) onTarget:self withObject:nil animated:YES];
}
- (void)capture {
//capture view
UIGraphicsBeginImageContextWithOptions(Sview.bounds.size, Sview.opaque, 0.0);
[Sview.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage * screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSString *str = [NSString stringWithFormat:#"some string"];
UIActivityViewController* activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:#[screenshot , str ]
applicationActivities:nil];
UIViewController *vc = self.view.window.rootViewController;
[vc presentViewController: activityViewController animated: YES completion:nil];
}
- (void)hudWasHidden:(MBProgressHUD *)hud {
// Remove HUD from screen when the HUD was hidded
[HUD removeFromSuperview];
HUD = nil;
}
This is how I use it:
[MBProgressHUD showHUDAddedTo: self.view animated: YES];
[self doVeryLongTask];
[MBProgressHUD hideHUDForView: self.view animated: YES];
Try to present this after removing HUD.
- (void)hudWasHidden:(MBProgressHUD *)hud {
// Remove HUD from screen when the HUD was hidded
[HUD removeFromSuperview];
HUD = nil;
UIViewController *vc = self.view.window.rootViewController;
[vc presentViewController: activityViewController animated: YES completion:nil];
}

How to add a 'cancel' button to a QuickDialog controller?

I am using the regular QuickDialog controller code from their tutorial:
QRootElement *root = [[QRootElement alloc] init];
root.title = #"Hello"
root.grouped = YES;
QSection *section = [[QSection alloc] init];
QEntryElement *hello = [[QEntryElement alloc] initWithTitle:#"Hello World" Value:#""];
[root addSection:section];
[info addElement:hello];
UINavigationController *navigation = [QuickDialogController controllerWithNavigationForRoot:root];
[self presentModalViewController:navigation animated:YES];
How can I add a 'cancel' button to the navigation bar? I tried:
navigation.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel handler:^(id sender){
[self.navigationController.modalViewController dismissModalViewControllerAnimated:YES];
}];
... but that didn't work. Any suggestions?
The proper way to do this is to adjust the code for the `leftBarButtonItem' like this:
navigation.navigationBar.topItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel handler:^(id sender){
[self.navigationController.modalViewController dismissModalViewControllerAnimated:YES];
}];
I know this is late but hopefully this will help someone else. I had a similar problem, and was able to use the following code to create a button to remove the form from view
navigation.navigationBar.topItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Close" style:UIBarButtonItemStyleDone target:self action:#selector(dismissModalViewControllerAnimated:)];
I tried your code in my sample logic and achieved the cancel button in the following way.
You need to set your navigationItem's leftbarbuttonitem on the viewcontroller of a navigation controller, instead of setting straight to your navigationcontroller.
// -- present your root controller.
UINavigationController *navigation = [QuickDialogController controllerWithNavigationForRoot:root];
[self presentModalViewController:navigation animated:YES];
[[[navigation topViewController] navigationItem] setLeftBarButtonItem:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel handler:^(id sender){
[self.navigationController dismissModalViewControllerAnimated:YES];
}]];

load custom view in MBProgressHUD

Is it possible to load a custom view in MBProgressHUD overlay, there is a custom view option with the MBProgressHUD class, but can i assign a XIB view etc with customView??
Yes you could do something like this:
MBProgressHUD *loadingHUD = [[MBProgressHUD alloc] init];
loadingHUD.mode = MBProgressHUDModeCustomView;
loadingHUD.labelText = nil;
loadingHUD.detailsLabelText = nil;
UIView *customView = [[UIView alloc] initWithFrame:self.view.bounds]; // Set a size
// Add stuff to view here
loadingHUD.customView = customView;
[HUD show:YES];

Resources