Xamarin.ios 在monotouch中查看颜色和背景

Xamarin.ios 在monotouch中查看颜色和背景,xamarin.ios,uialertview,Xamarin.ios,Uialertview,如何更改UIAlertView的颜色或/和背景。在objective-c中找到了一些例子,不知道如何在monotouch中应用它们。这应该可以让您开始了,您可能需要稍微调整一下图像帧,使其相对于背景图像正确 public class FooAlertView : UIAlertView { UIImageView imageView; public FooAlertView() { this.Title = "Alert!"; this.

如何更改UIAlertView的颜色或/和背景。在objective-c中找到了一些例子,不知道如何在monotouch中应用它们。这应该可以让您开始了,您可能需要稍微调整一下图像帧,使其相对于背景图像正确

public class FooAlertView : UIAlertView
{
    UIImageView imageView;

    public FooAlertView()
    {
        this.Title = "Alert!";
        this.Message = "Puppies are cute...";
        AddButton("OK!");
        imageView = new UIImageView(UIImage.FromFile("Images/popover/popoverBg.png"));
    }

    public override void Draw(RectangleF rect)
    {
        base.Draw(rect);

        foreach(var uiview in this.Subviews) {
            if(uiview.GetType() == typeof(UIImageView)) {

                uiview.RemoveFromSuperview();

                this.AddSubview(imageView);
                this.SendSubviewToBack(imageView);
            }
        }
    }
}

无需使用图像添加新的子视图。可以在图像视图中替换现有图像

  public override void Draw(RectangleF rect)
    {
        base.Draw(rect);
        foreach (var uiview in this.Subviews)
        {
            if (uiview.GetType() == typeof(UIImageView))
            {
                UIImageView imageView = uiview as UIImageView;
                if (imageView != null) imageView.Image = UIImage.FromFile("Images/header.png");

            }
        }
    }

出什么事了。。。它显示了图片,但它在蓝色边框后面。我需要改变那个框架的背景不。。。不是背景,最好说色调。我想保留那个漂亮的半透明框架,有漂亮的圆角和漂亮的边框。我只需要换一下颜色可怜的家伙,我今天不想给你更多的坏消息,但透明度、圆角和漂亮的边框只是苹果贴在一个UIButton和几个UILabel后面的平面图像。我编辑了答案以反映您的用例。