원본: http://iphonedevelopertips.com/user-interface/uialertview-without-buttons-please-wait-dialog.html
출처: http://www.devpia.com/MAEUL/Contents/Detail.aspx?BoardID=7462&MAEULNO=911&no=52368&page=1

If you’ve ever wanted to show a simple “please wait” dialog without resorting to a custom view, UIAlertView is a good option, and is even more appropriate if you customize the alert such that no buttons are shown.

In the figure below you can see how a simple alert can be shown (sans buttons) while you are busy doing some other system activity (reading/writing files, etc).


UIAlertView without Buttons
UIAlertView *alert;
 
...
 
alert = [[[UIAlertView alloc] initWithTitle:@"Configuring Preferences\nPlease Wait..." 
  message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
 
[alert show];

Trouble with this approach is that things look a little lopsided, as there is a significant amount of dead space on the bottom where the button(s) are to be shown. We can fix this by adding a few newline characters at the start of our message:

UIAlertView *alert;
 
...
 
// Add two newlines characters at the start of the message
alert = [[[UIAlertView alloc] initWithTitle:@"\n\nConfiguring Preferences\nPlease Wait..." 
  message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
 
[alert show];

The text is nearly centered, yet we’ve created a different problem, there is now white space on the top and bottom. There is one more approach…

UIAlertView with UIActivity Indicator

In the whitespace on the bottom, let’s add an activity indicator. Also, remove the newlines in the message text so the text starts near the top:

UIAlertView *alert;
 
...
 
alert = [[[UIAlertView alloc] initWithTitle:@"\n\nConfiguring Preferences\nPlease Wait..." 
  message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];

[alert show];
 
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] 
  initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

// Adjust the indicator so it is up a few pixels from the bottom of the alert
indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50);
[indicator startAnimating];
[alert addSubview:indicator];
[indicator release];

Dismissing the Buttonless UIAlertView

Since there are no buttons associated with the alert, we have to dismiss the alert ourselves, versus the traditional approach where the system dismisses the alert when a button is pressed.

Here is the call to dismiss the alert:

[alert dismissWithClickedButtonIndex:0 animated:YES];

'iOS > Skills' 카테고리의 다른 글

모달 뷰 사용(일종의 팝업 윈도우)  (1) 2010.11.23
애니메이션 주기  (0) 2010.11.10
MBProgressHUD  (0) 2010.07.21
UIBarButtonSystemItem 추가된 아이템  (0) 2010.07.21
UIAlertView 커스터마이징  (0) 2010.07.21
Posted by 독뽀
,