UIAlertView单色的颜色和背景

时间:2011-11-29 21:06:33

标签: xamarin.ios uialertview

如何更改UIAlertView的颜色和/或背景。在objective-c中找到了示例,dunno如何在monotouch中应用它们

2 个答案:

答案 0 :(得分:2)

这应该让你开始,你可能需要稍微调整图像框架,使其相对于你的背景图像正确。

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);
            }
        }
    }
}

答案 1 :(得分:0)

无需添加带图像的新子视图。您可以替换图像视图中的现有图像。

  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");

            }
        }
    }