iphone中的默认alertView没有背景颜色(iPhone)

时间:2011-06-25 09:23:27

标签: ios4

我在我的iPhone应用程序中使用默认警报视图已经很多次了。但是有时候它没有正常运行,它的背景颜色就像背景颜色一样(它只显示视图中的文字)。请帮助我。 谢谢你&问候   纳拉亚纳

1 个答案:

答案 0 :(得分:3)

尝试这种替代方案

同时查看此网址http://kwigbo.com/post/318396305/iphone-sdk-custom-uialertview-background-color

Background of AlertView is an image And you can change this image



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]];