弹出 多个 修改背景的 AlertView

来源:互联网 发布:拆卸软件是什么意思 编辑:程序博客网 时间:2024/06/11 18:33

 static UIAlertView *alert = nil;

 alert = [[UIAlertView alloc]  initWithTitle:promptTitle message:promptMessage delegate:target cancelButtonTitle:cancelBtnTitle otherButtonTitles:nil];     

  alert.delegate = target;
 alert.title = promptTitle;
 alert.message = promptMessage;
 
 for (NSString *str in otherBtnTitleArray) {
  [alert addButtonWithTitle:str];  
 }
 
// [alert show];
 // CGSize theSize;
//
// theSize = [alert frame].size;
//  
//  UIGraphicsBeginImageContext(theSize);   
// 
//  [theImage drawInRect:CGRectMake(0, 0, theSize.width, theSize.height)];   
//
//  theImage = UIGraphicsGetImageFromCurrentImageContext();   
// 
//  UIGraphicsEndImageContext();
//  
//  [[alert layer] setContents:(id)[theImage CGImage]];


 UIImage *theImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"alert.png" ofType:nil]];
 UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage:theImage];
 backgroundImageView.contentMode = UIViewContentModeScaleToFill;
 [alert addSubview:backgroundImageView]; 
 [alert sendSubviewToBack:backgroundImageView];
 [alert show];
 
 [alert release];

 参考:http://stackoverflow.com/questions/6692361/custom-alertview-with-background