【问题标题】:iphone UIAlertView - custom background coloriphone UIAlertView - 自定义背景颜色
【发布时间】:2010-12-13 18:50:35
【问题描述】:

我需要自定义 UIAlertView 的背景颜色。

我有一个在 iphone 3.x 上完美运行的示例代码,但在 iphone 4 上,alertview 显示默认的蓝色。

    UIAlertView *alertView = 
 [[[UIAlertView alloc] initWithTitle:@"Alerta"
        message:msg 
          delegate:nil
       cancelButtonTitle:@"OK" 
       otherButtonTitles:nil] autorelease];

 [alertView show];

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

 UILabel *theBody = [alertView valueForKey:@"_bodyTextLabel"];
 [theBody setTextColor:[UIColor whiteColor]];

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

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

 [[alertView layer] setContents:(id)theImage.CGImage];
[alertView show];

【问题讨论】:

    标签: iphone ios4 uialertview


    【解决方案1】:

    虽然很有可能,但不建议修改此类内容,因为简单的更新可能会破坏它。相反,尝试制作您自己的警报视图,正如 Nathan S. 所展示的那样:

    How can I customize an iOS alert view?

    【讨论】:

      猜你喜欢
      • 2013-05-18
      • 2011-09-12
      • 2010-10-27
      • 2018-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多