objective-c - 带背景的自定义 AlertView

标签 objective-c ios cocoa-touch uikit uialertview

各位,我需要在 UIAlertView 上设置一张图片..

enter image description here

我附上了我的 UIAlertview 和图像问题..

我用过这段代码行..

UIAlertView *theAlert = [[[UIAlertView alloc] initWithTitle:@"Atention"
   message: @"YOUR MESSAGE HERE", nil)
   delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease];

   [theAlert show];

   UILabel *theTitle = [theAlert valueForKey:@"_titleLabel"];
   [theTitle setTextColor:[UIColor redColor]];

   UILabel *theBody = [theAlert valueForKey:@"_bodyTextLabel"];
   [theBody setTextColor:[UIColor blueColor]];

   UIImage *theImage = [UIImage imageNamed:@"Background.png"];    
   theImage = [theImage stretchableImageWithLeftCapWidth:16 topCapHeight:16];
   CGSize theSize = [theAlert frame].size;

   UIGraphicsBeginImageContext(theSize);    
   [theImage drawInRect:CGRectMake(0, 0, theSize.width, theSize.height)];    
   theImage = UIGraphicsGetImageFromCurrentImageContext();    
   UIGraphicsEndImageContext();

   [[theAlert layer] setContents:[theImage CGImage]];

请解决这个问题.. 我只需要带有警报的图像..

最佳答案

试试这个...

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"UIAlert View" message:@"hello" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Close",nil];

UIImage *alertImage = [UIImage imageNamed:@"plus.png"];

UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage:alertImage];

backgroundImageView.frame = CGRectMake(0, 0, 282, 130);

backgroundImageView.contentMode = UIViewContentModeScaleToFill;

[alert addSubview:backgroundImageView];

[alert sendSubviewToBack:backgroundImageView]; 
[alert show];
[alert release];

关于objective-c - 带背景的自定义 AlertView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6692361/

相关文章:

ios - @IBAction 在 Swift 中使应用程序崩溃

ios - GMSMapView GroundOverlay 覆盖整个 MapView 边界

objective-c - 赋值运算符是否会生成 NSArray 的浅拷贝?

ios - UIDocument openWithCompletionHandler 未在 iOS 设备上完成

objective-c - 升级到 iOS8 后定位服务错误

ios - 有没有办法在 Objective-C 中识别两个图像是否几乎相同?

objective-c - 如何从异步 NSURLConnection 返回到调用类?

php - APNS:无效的 token 导致所有后续的推送通知失败

iphone - MKMapView - 删除注释导致应用程序崩溃

ios - 从 MDM 安装后企业应用程序崩溃