Adding Transparent Modal View Programatically– iPhone
by dkberktas on May 18th, 2010
Assuming you have a long processĀ taken so long that you want to show a transparent view, you can do it very easily by just adding the following method to your .m file and you will get the following transparent loading view
-(void)showLoadingView
{
CGRect transparentViewFrame = CGRectMake(0.0, 0.0,320.0,480.0);
transparentView = [[UIView alloc] initWithFrame:transparentViewFrame];
transparentView.backgroundColor = [UIColor lightGrayColor];
transparentView.alpha = 0.9;
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
spinner.center = transparentView.center;
[spinner startAnimating];
UILabel *messageLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 280, 320, 30)];
messageLabel.textAlignment = UITextAlignmentCenter;
messageLabel.text = @"please wait...";
[transparentView addSubview:spinner];
[transparentView addSubview:messageLabel];
[self.view addSubview:transparentView];
[messageLabel release];
[spinner release];
[transparentView release];
}
Now, you should call this function whenever needed. Let’s say you have a background process that will run while the transparent loading view is shown, below is the code to handle this situation:
-(void)myAction:(id)sender
{
[self showLoadingView];
[self performSelectorInBackground:@selector(myActionBackground:) withObject:sender];
}
-(void)myActionBackground:(id)sender
{
NSAutoreleasePool *apool = [[NSAutoreleasePool alloc] init];
//your code
[apool release];
}
No comments yet






