Add UIActivityIndicatorView to UIActionSheet - ios

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);

Related

UIAlertView loading indicator is almost offside?

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];

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.

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

how to manage uipickerview in uiactionsheet

i am trying to show the UIPickerView in UIActionSheet . from the below mentioned code it works great in portrait mode but looks wired in Landscape Mode. (my app support iPhone 4/5 n landscape orientation also).
what i am doing wrong ?
actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:nil
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
CGRect pickerFrame=CGRectMake(0, 40, 0, 0);
UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame];
pickerView.showsSelectionIndicator = YES;
pickerView.dataSource = self;
pickerView.delegate = self;
[actionSheet addSubview:pickerView];
UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:#"OK"]];
closeButton.momentary = YES;
closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
closeButton.tintColor = [UIColor blackColor];
[closeButton addTarget:self action:#selector(dismissActionSheet:) forControlEvents:UIControlEventValueChanged];
[actionSheet addSubview:closeButton];
[actionSheet showInView:self.view];
[actionSheet setBounds:CGRectMake(0, 0, 320, 485)];
Finally i got the solution
First of all i have to set the width of the picker view as i have mentioned
CGRect pickerFrame=CGRectMake(0, 40, 0, 0);
so it can be like
CGRect pickerFrame=CGRectMake(0, 40, 320, 0);
I found one more good solution :
Just call the picker view in action sheet by clicking a text field:
self.textField.inputView = yourCustomView;

UIPicker / UIActionSheet works fine on iPhone but only thin line on iPad

The following Code works fine on iPhone, but not on iPad. Only get a thin line instead of the full view. Have been researching and maybe something with the rect for the picker? All size numbers seem to be reasonable.
actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil
cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
CGRect pickerFrame = CGRectMake(0, 40, 0, 0);
if ( isipad ) pickerFrame = CGRectMake(0, 345, 400, 216);
pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame];
pickerView.showsSelectionIndicator = YES;
pickerView.dataSource = self;
pickerView.delegate = self;
[actionSheet addSubview:pickerView];
[pickerView release];
UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:#"Select"]];
closeButton.momentary = YES;
closeButton.frame = CGRectMake(10, 7.0f, 100.0f, 30.0f);
closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
closeButton.tintColor = [UIColor blackColor];
[closeButton addTarget:self action:#selector(dismissActionSheet:) forControlEvents:UIControlEventValueChanged];
[actionSheet addSubview:closeButton];
[closeButton release];
UISegmentedControl *skipButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:#"Skip Birth Year"]];
skipButton.momentary = YES;
skipButton.frame = CGRectMake(200, 7.0f, 100.0f, 30.0f);
skipButton.segmentedControlStyle = UISegmentedControlStyleBar;
skipButton.tintColor = [UIColor blackColor];
[skipButton addTarget:self action:#selector(skipActionSheet:) forControlEvents:UIControlEventValueChanged];
[actionSheet addSubview:skipButton];
[skipButton release];
[actionSheet setBounds:CGRectMake(0, 0, self.view.frame.size.width, 216)];
[actionSheet showInView:self.view];
[actionSheet setBounds:CGRectMake(0, 0, self.view.frame.size.width, 216)];
Well, got it to work by putting most of the code in
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
including
pickerFrame = CGRectMake(0, 0, 320, 214);
AND
initWithTitle:#"\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
for the action sheet. Magic I guess.
Is this correct:
CGRect pickerFrame = CGRectMake(0, 40, 0, 0); //This line sets the frame height and width equal to 0.
if ( isipad ) pickerFrame = CGRectMake(0, 345, 400, 216);
Is your isipad bool working ok?
Thanks for your post ort11.
I needed to make an iPad app and I did working copy-paste code from iPhone app and on iPad is the same: a small line :)
My needs is a language chooser only, nothing else.
Here are the codes based on your answer:
- (IBAction)btLanguageChooserPressed {
NSLog(#"btLanguageChooserPressed");
[self createLanguageSheet];
// show the sheet: will be invoked the willPresentActionSheet method
[sheet showInView:self.view];
}
- (void)createLanguageSheet {
NSLog(#"createLanguageSheet()");
// hoolly crap, need to initialize the title with: #"\n\n\n\n\n\n\n\n\n\n\n\n\n\n" to get working!!!
sheet = [[UIActionSheet alloc] initWithTitle:#"\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
[sheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
}
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
{
CGRect pickerFrame = CGRectMake(0, 0, 320, 216);
pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame];
pickerView.showsSelectionIndicator = YES;
pickerView.dataSource = self;
pickerView.delegate = self;
[sheet addSubview:pickerView];
// add close button:
UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:#"OK"]];
closeButton.momentary = YES;
closeButton.frame = CGRectMake(120, 12, 100, 30);
closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
closeButton.tintColor = [UIColor blackColor];
[closeButton addTarget:self action:#selector(dismissSheet:) forControlEvents:UIControlEventValueChanged];
[sheet addSubview:closeButton];
[sheet setBounds:CGRectMake(0, 0, self.view.frame.size.width, 216)];
//[sheet showInView:self.view];//already called, why need again?
//[sheet setBounds:CGRectMake(0, 0, self.view.frame.size.width, 216)];
}
at runtime I do a cache in a variable:
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
NSLog(#"Selected: %#", [arrayLanguages objectAtIndex:row]) ;
selectedRow = row;
}
and here is the finish:
- (void)dismissSheet:(id)sender {
[sheet dismissWithClickedButtonIndex:0 animated:YES];
NSString* selectedLanguage = [arrayLanguages objectAtIndex:selectedRow];
NSLog(#"dismissSheet() selectedLanguage: %#",selectedLanguage);
switch (selectedRow) {
case 0://English
imgCurrentLanguage.image = [UIImage imageNamed:#"english.png"];
break;
case 1:// Deutsch
break;
case 2://Français
break;
case 3://Italiano
break;
case 4://Español
break;
default:
break;
}
// TODO: do the changes in GUI
}
I am not able to move this actionsheet from the center of the screen to botton- left corner. But I am trying...
I think this would be the cleanest solution :
#interface MyActionSheet : UIActionSheet
#property (nonatomic, strong) IBOutlet UIView * customView;
#end
#implementation MyActionSheet
-(CGRect)bounds {
return self.customView.bounds;
}
#end
then:
MyActionSheet * s = [[MyActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
s.customView = _auxView;
[s addSubview:_auxView];

Resources