创建没有按钮的UIAlertView

默认的,UIAlertView都有一个或者多个按钮,如果你想创建没有按钮的UIAlertView,可以使用以下的方法:

  1.  
  2. UIAlertView *alert; 
  3. alert = [[[UIAlertView alloc] initWithTitle:@"Configuring Preferences\nPlease Wait…"
  4.   message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
  5.  
  6. [alert show];
  7.  

上面的标题可能有些靠上,可以用过给标题增加回车的方式,使标题居中:

  1.  
  2. UIAlertView *alert; 
  3. alert = [[[UIAlertView alloc] initWithTitle:@"\n\nConfiguring Preferences\nPlease Wait…"
  4.   message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
  5.  
  6. [alert show];
  7.  

如果你还想给UIAlertView添加一个等待提示符,则可以这么做:

  1.  
  2. UIAlertView *alert; 
  3. alert = [[[UIAlertView alloc] initWithTitle:@"Configuring Preferences\nPlease Wait…" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
  4. [alert show];
  5.  
  6. UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
  7.  
  8. // Adjust the indicator so it is up a few pixels from the bottom of the alert
  9. indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height – 50);
  10. [indicator startAnimating];
  11. [alert addSubview:indicator];
  12. [indicator release];
  13.  

解除UIAlertView的显示

设置定时器[NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(performDismiss) userInfo:nil repeats:NO];

调用如下方法:

- (void)performDismiss {
    [baseAlert dismissWithClickedButtonIndex:0 animated:NO];
}

http://blog.prosight.me/index.php/2010/02/580

posted @ 2010-10-22 21:34  周宏伟  阅读(2486)  评论(0编辑  收藏  举报