我想更改UIAlertView的背景颜色,但这似乎没有color属性。

最佳答案

AlertView的背景是图像
您可以更改此图像

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

关于iphone - 更改UIAlertView的背景颜色?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/883208/

10-08 20:59