UIAlertView loading indicator is almost offside? - ios

I have following code:
_loadingAlert = [[UIAlertView alloc] initWithTitle:ALERT_TITLE_LOADING
message:ALERT_MESSAGE_LOADING
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:nil];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[indicator startAnimating];
[_loadingAlert setValue:indicator forKey:#"accessoryView"];
[_loadingAlert show];
Result:
My purpose is to display an alertview with loading indicator inside but the result is as attached screenshot. Anyone has idea?

Try with this code (as suggested by #A-Live), you can adjust the padding value to add more space at the bottom of the activity indicator.
_loadingAlert = [[UIAlertView alloc] initWithTitle:ALERT_TITLE_LOADING
message:ALERT_MESSAGE_LOADING
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:nil];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
indicator.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
indicator.translatesAutoresizingMaskIntoConstraints = YES;
[indicator startAnimating];
CGFloat padding = 15;
UIView *indicatorView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, indicator.frame.size.width, indicator.frame.size.width+padding)];
[indicatorView addSubview:indicator];
[_loadingAlert setValue:indicatorView forKey:#"accessoryView"];
[_loadingAlert show];

Related

How to create UIProgressViewStyleBar on UIAlertview iOS 7?

I am trying to create UIProgressViewStyleBar on UIAlertview with JSON loading status info on my app. Now my problem is I cant see UIProgressViewStylebar on iOS 7. Please help me!
My Source:
UIAlertView *alertss = [[UIAlertView alloc] initWithTitle:#"Please Wait..Downloading reports..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] ;
alertss.frame=CGRectMake(50, 50, 280, 40);
UIProgressView *prgView = [[UIProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleBar];
prgView.frame = CGRectMake(5, 0, 70, 20);
prgView.hidden=NO;
[alertss addSubview:prgView];
[alertss show];
UILabel *statusLabel = [[UILabel alloc] init];
statusLabel.backgroundColor = [UIColor clearColor];
statusLabel.textColor = [UIColor whiteColor];
statusLabel.font = [UIFont fontWithName:#"AmericanTypewriter-Condensed" size:18.0];
statusLabel.frame = CGRectMake(120, 80, 80, 20);
[alertss addSubview:statusLabel];
[alertss show];
Yeah that is the correct code with that code add this line
[progressView setProgress:0.75f animated:YES];
before showing your alert. change the progress value depends on your need. or animate it if you want.
UIAlertView *av = [[UIAlertView alloc] initWithTitle:#"Running" message:#"" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:nil];
UIProgressView* progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
progressView.frame = CGRectMake(0, 0, 200, 15);
progressView.bounds = CGRectMake(0, 0, 200, 15);
progressView.backgroundColor = [UIColor blackColor];
[progressView setUserInteractionEnabled:NO];
[progressView setTrackTintColor:[UIColor blueColor]];
[progressView setProgressTintColor:[UIColor redColor]];
[progressView setProgress:0.75f animated:YES];
// you have to set the accessoryView to alertview
[av setValue:progressView forKey:#"accessoryView"];
[av show];
see adding MBprogressHUD is so simple. first download the MBProgressHUD Lib from the GitHub and import in your project as #import "MBProgressHUD.h"
And then simple line to show the progressHUD is as follows :
to show:
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
to hide:
[MBProgressHUD hideHUDForView:self.view animated:YES];
for your problem use this code:
av = [[UIAlertView alloc] initWithTitle:#"Running" message:#"" delegate:self cancelButtonTitle:#"Done" otherButtonTitles:nil];
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
[av show];
[MBProgressHUD hideHUDForView:self.view animated:YES];
Here I used the circular loader. if you want to customise it you can use this loader in many forms as you wish.

checkbox in uialertview in ios8

I want to add checkbox exactly as the below image
below is my code:
UIButton *nameField = [[UIButton alloc] initWithFrame:CGRectMake(120, 0, 30, 30.0)];
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 250, 50)];
[v setBackgroundColor:[UIColor clearColor]];
[nameField setImage:[UIImage imageNamed:#"unchecked.png"] forState:UIControlStateNormal];
[v addSubview:nameField];
UIAlertView *av = [[UIAlertView alloc] initWithTitle:#"Delete selected pods from server?" message:
#"" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"OK", nil];
[av setValue:v forKey:#"accessoryView"];
av.message = #"This will delete all the posts related to the pictures you want to delete!";
[av show];
with the above code I am getting as :
I want to get checkbox beside message..
Any help or suggestion how to proceed?
You can use https://github.com/wimagguc/ios-custom-alertview
Create your custom content view and set it like
CustomIOS7AlertView *alertView = [[CustomIOS7AlertView alloc] init];
UIView *customView ..; //Your custom view
[alertView setContainerView:customView];
I would suggest you to do not do that.
accessoryView is not a public exposed API and you risk an app rejection
UIAlertView is deprecated in iOS8, use UIAlertController
You can use a third party library, I usually integrate MRProgress in my projects, you can create your own nib and add it.

Adding UIActivityIndicatorView to UIAlertView

I want to add an activity indicator inside the message , the uiAlert message, i tried basically everything on the internet, and nothing worked for me, i will just have the uialertview alone , here's my code
UIAlertView *waitAlert = [[UIAlertView alloc] initWithTitle:#"Please Wait...." message:#"\n\n" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
UIActivityIndicatorView *progress= [[UIActivityIndicatorView alloc] initWithFrame: CGRectMake(125, 50, 30, 30)];
progress.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
progress.color = [UIColor blackColor];
[waitAlert addSubview: progress];
[progress startAnimating];
[waitAlert show];
This is what i end up having
what am i missing!?
in iOS 7 you cannot addSubview anything on UIAlertView,that was possible till iOS 6.1.so MBProgressHud is the best and simple solution for that
Try to add your UIActivityIndicator using the UIAlertViewDelegate method:
- (void)didPresentAlertView:(UIAlertView *)alertView
{
UIActivityIndicatorView *progress = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
progress.frame = CGRectMake(125, 50, 30, 30);
[progress startAnimating];
[alertView addSubview:progress];
}

Add UIActivityIndicatorView to UIActionSheet

I am trying to add an UIActivityIndicatorView to UIActionsSheet in this way:
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:nil
delegate:sharedInstance
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
for(NSMutableDictionary *dict in moreStructure)
{
NSString *value = [dict valueForKey:TITLE_PARAMETER];
[actionSheet addButtonWithTitle:value];
}
[actionSheet addButtonWithTitle:#"Cancel"];
actionSheet.cancelButtonIndex = [moreStructure count];
[actionSheet showInView:((SectionViewController *)sharedInstance.currentViewController).view];
UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityView.frame = CGRectMake(100, 500, 15, 15);
[activityView startAnimating];
[actionSheet addSubview:activityView];
When the UIActionSheet appears, however, I do not see an UIActivityIndicatorView on it. Please, help me.
I have try this and this is working... Please check frame of activityView... because its y is 500...
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:nil
delegate:nil
cancelButtonTitle:#"Test"
destructiveButtonTitle:#"Test"
otherButtonTitles:nil];
[actionSheet showInView:self.view];
UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityView.frame = CGRectMake(100, 5, 15, 15);
[activityView startAnimating];
[actionSheet addSubview:activityView];
activityView.backgroundColor = [UIColor redColor];
actionSheet.backgroundColor = [UIColor greenColor];
activityView.frame = CGRectMake(100, 500, 15, 15);
// this so this above must change
activityView.frame = CGRectMake(10, 50, 300, 400);

UIPickerView not scrolling in actionSheet

I've added an UIPickerView into a UIActionSheet. Everything ok, but my picker can't be scrolled to choose a value. Any suggestions?
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
UIPickerView * picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 50, 320, 270)];
picker.showsSelectionIndicator = YES;
picker.dataSource = self;
picker.delegate = self;
[actionSheet addSubview:picker];
[picker release];
[actionSheet showInView:self.view];
[actionSheet setBounds:CGRectMake(0, 0, 320, 500)];
[actionSheet release];
Best regards,
Dorin
An alternative solution to what you're trying to achieve is to set text field's inputView and inputAccessoryView. Setting these will replace the standard keyboard and bring in custom views. This includes the picker view. I happened to write a short example in this question here. Take a look and see if it helps.

Resources