Since i am new in iPhone i am having a litle problem. I want to use UIActivityIndicatorView in my application. Since I have bee succesfull using indicatorView but I want to display the IndicatorView with a Blur Background so that i could not click on the button on my Current activity.
Please Friends
Guide me to some tutorial or some code.
Thanks a bunch in advance
Here you go this is my implementation but you can modify. Post the code in app Delegate and use anywhere in you application.
#pragma mark -
#pragma mark Waiting View
- (void)showWaitingView {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
CGRect frame = CGRectMake(90, 190, 32, 32);
UIActivityIndicatorView* progressInd = [[UIActivityIndicatorView alloc] initWithFrame:frame];
[progressInd startAnimating];
progressInd.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
frame = CGRectMake(130, 193, 140, 30);
UILabel *waitingLable = [[UILabel alloc] initWithFrame:frame];
waitingLable.text = #"Processing...";
waitingLable.textColor = [UIColor whiteColor];
waitingLable.font = [UIFont systemFontOfSize:20];;
waitingLable.backgroundColor = [UIColor clearColor];
frame = [[UIScreen mainScreen] applicationFrame];
UIView *theView = [[UIView alloc] initWithFrame:frame];
theView.backgroundColor = [UIColor blackColor];
theView.alpha = 0.7;
theView.tag = 999;
[theView addSubview:progressInd];
[theView addSubview:waitingLable];
[progressInd release];
[waitingLable release];
[window addSubview:[theView autorelease]];
[window bringSubviewToFront:theView];
[pool drain];
}
- (void)removeWaitingView {
UIView *v = [window viewWithTag:999];
if(v) [v removeFromSuperview];
}
First, you have to add a view with a black background and alpha of 0.3 or something. Then add the activity indicator above the view.
// an example
[self.view addSubview:aSemiTransparentBlackView];
[self.view addSubview:activityIndicator];
can try this also:
-(UIAlertView *)showActivityIndicator :(NSString *)message
{
alertViewProgress = [[UIAlertView alloc] initWithTitle:message message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
UIActivityIndicatorView *activity =[[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(120,50,37,37)];
activity.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[activity startAnimating];
[alertViewProgress addSubview:activity];
[activity release];
[alertViewProgress show];
return alertViewProgress;
}
Related
I am trying to display an activity indicator in full screen so the user cannot press any button in the screen till the activity indicator is turned off as the alert view process. I have called the [activityView startAnimating] but I can push the buttons in the back. Is there way to prevent that?
Thanks from now.
You can use MBProgressHUD for such loading indictators. It's a great MIT-licensed class that extends well if you want to customize it further.
you can try this
UIAlertView *alert= [[[UIAlertView alloc] initWithTitle:#"Loading\nPlease Wait..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
[alert show];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
indicator.center = CGPointMake(150, 100);
[indicator startAnimating];
[alert addSubview:indicator];
[indicator release];
and add this line where you want remove your alert
[alert dismissWithClickedButtonIndex:0 animated:YES];
I'll suggest a best way will be displaying an alertView with activity indicator on the screen.
You can use the following code for this:
declare property for UIAlertView like:
#property (nonatomic, strong) UIAlertView *sendAlert;
self.sendAlert = [[UIAlertView alloc] initWithTitle:#"Loading" message:#"" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
UIActivityIndicatorView *act = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
act setFrame:CGRectMake(115, 60, 50, 50)];
[act startAnimating];
[sendAlert addSubview:act];
act = nil;
[sendAlert show];
When you want to remove alert you can use:
[sendAlert dismissWithClickedButtonIndex:0 animated:YES];
sendAlert = nil;
Another alternative, you can add the activity indicator to your view itself and set the userInteraction of backbutton to false. When you finish the task set to True. But It won't be a nice way.
hey for your this requirement use the bellow code which you can access in your every view use..
add this bellow code and object in AppDelegate.h file like bellow..
UIView *activityView;
UIView *loadingView;
UILabel *lblLoad;
and paste this bellow code in AppDelegate.m file
#pragma mark - Loading View
-(void) showLoadingView {
//NSLog(#"show loading view called");
if (loadingView == nil)
{
loadingView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 60.0, 320.0, 420.0)];
loadingView.opaque = NO;
loadingView.backgroundColor = [UIColor darkGrayColor];
loadingView.alpha = 0.5;
UIView *subloadview=[[UIView alloc] initWithFrame:CGRectMake(84.0, 190.0,150.0 ,50.0)];
subloadview.backgroundColor=[UIColor blackColor];
subloadview.opaque=NO;
subloadview.alpha=0.8;
subloadview.layer.masksToBounds = YES;
subloadview.layer.cornerRadius = 6.0;
lblLoad=[[UILabel alloc]initWithFrame:CGRectMake(50.0, 7.0,80.0, 33.0)];
lblLoad.text=#"LoadingView";
lblLoad.backgroundColor=[UIColor clearColor];
lblLoad.textColor=[UIColor whiteColor];
[subloadview addSubview:lblLoad];
UIActivityIndicatorView *spinningWheel = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(10.0, 11.0, 25.0, 25.0)];
[spinningWheel startAnimating];
spinningWheel.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
[subloadview addSubview:spinningWheel];
[loadingView addSubview:subloadview];
[spinningWheel release];
}
[self.window addSubview:loadingView];
//[[UIApplication sharedApplication] registerForRemoteNotificationTypes: UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert];
}
-(void) hideLoadingView {
if (loadingView) {
[loadingView removeFromSuperview];
[loadingView release];
loadingView = nil;
}
}
and call this method when you want in any class , just like bellow..
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate showLoadingView];
Add a UIView above your current view when activity indicator starts :
UIView *overlayView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
overlayView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
[self.navigationController.view addSubview:overlayView];
I search for a lot forums but nothing found, my problem is that
I need preload some data from the web to load to the UITableView.
I saw some apps solved this problem, when show UITableView they shows "waiting circle" as modal view and after data is loaded just hide this circle.
Is there simple solution to do this?
What I need to do?
What kind of Request do I need: synchronius or asynchronius?
How to show this circle, do I need to show animatedGif or there is some internal/external control for this?
You need to make a NSThread for your "waiting circle"-(Activity Indicator).
1)Threads How do I create an NSThread that isn't the main thread.
2)Activity Indicator How to use activity indicator view.
- (void)showWaitingView {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
CGRect frame = CGRectMake(90, 190, 32, 32);
UIActivityIndicatorView* progressInd = [[UIActivityIndicatorView alloc] initWithFrame:frame];
[progressInd startAnimating];
progressInd.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
frame = CGRectMake(130, 193, 140, 30);
UILabel *waitingLable = [[UILabel alloc] initWithFrame:frame];
waitingLable.text = #"Processing...";
waitingLable.textColor = [UIColor whiteColor];
waitingLable.font = [UIFont systemFontOfSize:20];;
waitingLable.backgroundColor = [UIColor clearColor];
frame = [[UIScreen mainScreen] applicationFrame];
UIView *theView = [[UIView alloc] initWithFrame:frame];
theView.backgroundColor = [UIColor blackColor];
theView.alpha = 0.7;
theView.tag = 999;
[theView addSubview:progressInd];
[theView addSubview:waitingLable];
[progressInd release];
[waitingLable release];
[window addSubview:[theView autorelease]];
[window bringSubviewToFront:theView];
[pool drain];
}
- (void)removeWaitingView {
UIView *v = [window viewWithTag:999];
if(v) [v removeFromSuperview];
}
I have the code below in my app. I show a UIPickerView with options, and I have a TextView placed on the same UIViewController .
when the picker is shown with options, the rest of the view seems not in focus and only when I resign the uipicker, the entire view gets focus.
what is the problem here?
-(void)viewWillAppear:(BOOL)animated {
myActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
UIPickerView *pickerViewCountry = [[UIPickerView alloc] init];
pickerViewCountry.showsSelectionIndicator = YES;
pickerViewCountry.dataSource = self;
pickerViewCountry.delegate = self;
pickerViewCountry.frame = CGRectMake(0,35 , 320, 15);
[myActionSheet addSubview:pickerViewCountry];
[pickerViewCountry release];
closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:#"Done"]];
closeButton.momentary = YES;
closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 27.0f);
closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
closeButton.tintColor = [UIColor blackColor];
[closeButton addTarget:self action:#selector(hidePicker) forControlEvents:UIControlEventValueChanged];
[myActionSheet addSubview:closeButton];
[closeButton release];
[myActionSheet showInView:self.view];
[myActionSheet setBounds:CGRectMake(0, 0, 320, 250)];
UITextView *myTextView = [[UITextView alloc] init];
myTextView.frame = CGRectMake(100, 12, 210, 20);
myTextView.layer.borderWidth = 1.0f;
myTextView.layer.cornerRadius = 5;
myTextView.clipsToBounds = YES;
myTextView.layer.borderColor = [[UIColor grayColor] CGColor];
myTextView.text = #"some text";
[self.view addSubview:myTextView];
[myTextView sizeToFit];
}
You've placed your UIPickerView inside UIActionSheet. That's standart behavior for UIActionSheet. Try to use keyboardView instead like so:
UITextField* dummyTextField = [[UITextField alloc]initWithFrame:CGRectMake(0, -20, 10, 10)];//the point is to put it outside visible view
dummyTextField.inputView = pickerViewCountry;
[dummyTextField becomeFirstResponder];//call to appear
[dummyTextField resignFirstResponder];//call do disappear
and for the buttons you can use folloving:
dummyTextField.inputAccessoryView = <some toolbar with buttons or any other view>
Happy coding :)
I will suggest you one solution with custom View.
datePickerContainer is UIView:
//datepicker
datePickerContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 440, 310, 300)];
datePickerContainer.opaque = YES;
datePickerContainer.backgroundColor = [UIColor clearColor];
UIImageView *pickerNavBar = [[UIImageView alloc] init];
UIImage *barImage = [UIImage imageNamed:#"pickerbar.png"];
pickerNavBar.image = barImage;
pickerNavBar.frame = CGRectMake(0, 7, barImage.size.width, barImage.size.height);
[datePickerContainer addSubview:pickerNavBar];
[pickerNavBar release];
UIButton* blueButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[blueButton setTitle:#"Done" forState: UIControlStateNormal];
blueButton.frame = CGRectMake(255, 15, 55, 30);
[blueButton addTarget:self action:#selector(hidePickerViewContainer) forControlEvents:UIControlEventTouchUpInside];
[datePickerContainer addSubview:blueButton];
[blueButton release];
//UIPickerView Initialization code
UIPickerView *pickerViewCountry = [[UIPickerView alloc] init];
pickerViewCountry.showsSelectionIndicator = YES;
pickerViewCountry.dataSource = self;
pickerViewCountry.delegate = self;
pickerViewCountry.frame = CGRectMake(0,35 , 320, 15);
[datePickerContainer addSubview:pickerViewCountry];
[pickerViewCountry release];
//set container and release
[self.view addSubview: datePickerContainer];
[datePickerContainer release];
To show datePickerContainer UIVie use this code:
-(void)showPickerViewContainer{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.4];
CGRect frameContainer = datePickerContainer.frame;
frameContainer.origin.y = 150.0f;
datePickerContainer.frame = frameContainer;
[UIView commitAnimations];
}
To handle done button and hide pickerView use this:
-(void)hidePickerViewContainer{
//here use you custom code to handle done action
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.4];
CGRect frameContainer = datePickerContainer.frame;
frameContainer.origin.y = 440.0f;
datePickerContainer.frame = frameContainer;
[UIView commitAnimations];
}
This is just a custom solution. Hope this help.
declare variable in header file
UIActionSheet *actionSheet;
NSString *pickerType;
Write Below code into your implementation file:
- (void)createActionSheet {
if (actionSheet == nil) {
// setup actionsheet to contain the UIPicker
actionSheet = [[UIActionSheet alloc] initWithTitle:#"Select"
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
UIToolbar *pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
pickerToolbar.barStyle = UIBarStyleBlackOpaque;
[pickerToolbar sizeToFit];
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
[barItems addObject:flexSpace];
[flexSpace release];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(pickerDone:)];
[barItems addObject:doneBtn];
[doneBtn release];
[pickerToolbar setItems:barItems animated:YES];
[barItems release];
[actionSheet addSubview:pickerToolbar];
[pickerToolbar release];
[actionSheet showInView:self.view];
[actionSheet setBounds:CGRectMake(0,0,320, 464)];
}
}
-(IBAction)BtnPressed:(id)sender
{
[self createActionSheet];
pickerType = #"picker";
select = NO;
UIPickerView *chPicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0, 44.0, 0.0, 0.0)];
chPicker.dataSource = self;
chPicker.delegate = self;
chPicker.showsSelectionIndicator = YES;
[actionSheet addSubview:chPicker];
sessoTxt.text = [sessoArray objectAtIndex:0];
[chPicker release];
}
declare delegate methods
#pragma mark UIPickerViewDelegate Methods
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
int count;
if ([pickerType isEqualToString:#"picker"])
count = [array count];
return count;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
NSString *string;
if ([pickerType isEqualToString:#"picker"])
string = [array objectAtIndex:row];
return string;
}
// Set the width of the component inside the picker
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
return 300;
}
// Item picked
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
select = YES;
if ([pickerType isEqualToString:#"picker"])
{
Txt.text = [array objectAtIndex:row];
}
}
- (void)pickerDone:(id)sender
{
if(select == NO)
{
if ([pickerType isEqualToString:#"picker"])
{
Txt.text = [array objectAtIndex:0];
}
}
[actionSheet dismissWithClickedButtonIndex:0 animated:YES];
[actionSheet release];
actionSheet = nil;
}
}
In my app when I download something from service, I show progress indicator:
- (void)setupProgressIndicator {
MBProgressHUD *progressHUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:progressHUD];
self.progressIndicator = progressHUD;
[progressHUD release];
}
[self.progressIndicator show:YES];
My view has Navigation Bar which I setup in my AppDelegate, and when indicator is shown, I still can tup on Navigation Bar Buttons...Can MBProgressHUB cover whole screen ??? Because I don't want to disable buttons on sync start and than make them enable on sync finish...I think indicator should cover whole screen. Any ideas ? Thanks...
Here is my implementation use it if you want
Put it in appDelegate and use from anywhere in the application.
#pragma mark -
#pragma mark Waiting View
- (void)showWaitingView {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
CGRect frame = CGRectMake(90, 190, 32, 32);
UIActivityIndicatorView* progressInd = [[UIActivityIndicatorView alloc] initWithFrame:frame];
[progressInd startAnimating];
progressInd.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
frame = CGRectMake(130, 193, 140, 30);
UILabel *waitingLable = [[UILabel alloc] initWithFrame:frame];
waitingLable.text = #"Processing...";
waitingLable.textColor = [UIColor whiteColor];
waitingLable.font = [UIFont systemFontOfSize:20];;
waitingLable.backgroundColor = [UIColor clearColor];
frame = [[UIScreen mainScreen] applicationFrame];
UIView *theView = [[UIView alloc] initWithFrame:frame];
theView.backgroundColor = [UIColor blackColor];
theView.alpha = 0.7;
theView.tag = 999;
[theView addSubview:progressInd];
[theView addSubview:waitingLable];
[progressInd release];
[waitingLable release];
[window addSubview:[theView autorelease]];
[window bringSubviewToFront:theView];
[pool drain];
}
- (void)removeWaitingView {
UIView *v = [window viewWithTag:999];
if(v) [v removeFromSuperview];
}
usual thing is to add an transparent view cover the entire screen and that will capture touch event. or you can make your HUD the size of the screen, with visible widget only in the center.
- (IBAction)showWithCustomView:(id)sender {
HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];
HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"37x-Checkmark.png"]] autorelease];
HUD.customView.frame=CGRectMake(0, 0, 320, 460);//Ur answer
HUD.mode = MBProgressHUDModeCustomView;
HUD.delegate = self;
HUD.labelText = #"Completed";
[HUD show:YES];
[HUD hide:YES afterDelay:3];
}
Here I'm gettimg memory allocation problem at activity indicator and my code is:
- (id)init {
if (self = [super init]) {
self.title=#"Release Details";
contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
contentView.backgroundColor = [UIColor clearColor];
self.view = contentView;
[contentView release];
CGRect frame = CGRectMake(0,0, 320,1500);
containerView = [[UIView alloc] initWithFrame:frame];
webView = [ [UIWebView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
webView.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:#"background1.png"]];
webView.delegate = self;
[containerView addSubview:webView];
CGRect activityViewframe = CGRectMake(20,8,20, 20);
progressInd = [[UIActivityIndicatorView alloc] initWithFrame:activityViewframe];
progressInd.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
progressInd.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleBottomMargin);
[containerView addSubview:progressInd];
[progressInd startAnimating];
progressInd.hidden = NO;
[progressInd stopAnimating];
[self.view addSubview:containerView];
isFetch=YES;
}
return self;
}
-(void) displayInProgressRightBarButton
{
UIView* rightBarButtonView = [ [UIView alloc] initWithFrame:CGRectMake(270,5,45, 35)];
[rightBarButtonView addSubview:progressInd];
UIBarButtonItem* buttonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBarButtonView];
self.navigationItem.rightBarButtonItem = buttonItem;
[rightBarButtonView release];
[buttonItem release];
}
- (void)webViewDidStartLoad:(UIWebView *)webView
{
[self displayInProgressRightBarButton];
[progressInd startAnimating];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[progressInd stopAnimating];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
Also I released the progressInd in dealloc eventhough it showing memory allocation at
progressInd = [[UIActivityIndicatorView alloc] initWithFrame:activityViewframe];
in init.
can anyone help me to solve this.
Anyone's help will be much Appreciated.
You can (and should) release it right after adding it to the container view:
[containerView addSubview:progressInd];
[progressInd release];
The same for the container view itself:
[self.view addSubview:containerView];
[containerView release];
The containing view will retain the subview for you, so you can release it right after adding it.