2011-11-29 95 views

回答

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

有什么问题......它显示图片,但它是在蓝色框架后面。我需要改变那个框架的背景 – Agzam

+0

不...不是背景,更好说色调。我想保留漂亮的圆角和美丽的边框的漂亮的半透明框架。我只是需要改变颜色 – Agzam

+2

可怜的家伙,我不想今天给你更多坏消息,但透明度,圆角和美丽的边界只是苹果在UIButton和几个UILabels背后的一个平面图像。我编辑了答案以反映你的用例。 – Anuj

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

      } 
     } 
    }