iphone - 更改 UIAlertView 的背景颜色?

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

最佳答案

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

https://stackoverflow.com/questions/883208/

相关文章:

objective-c - 在 Objective-C 中定义协议(protocol)的类别?

ios - 切换隐私设置将杀死应用程序

iphone - 如何在我的 Objective-C 源代码中转义 Unicode 字符?

ios - 仅在 Testflight 构建时应用程序崩溃

iphone - Objective-C 中的实例变量是否默认设置为 nil?

ios - swift 中的@property/@synthesize 等价物

iphone - 如何以编程方式创建 UIScrollView?

ios - 静态和动态单元格的 UITableView 混合?

iphone - NSDateFormatter,我做错了什么还是这是一个错误?

iphone - Objective-C - 将 float 转换为字符串的其他方法