1
如何更改UIAlertView的颜色和/或背景。在objective-c中找到的例子,不知道如何将它们应用于单点触摸UIAlertView颜色和单色背景
如何更改UIAlertView的颜色和/或背景。在objective-c中找到的例子,不知道如何将它们应用于单点触摸UIAlertView颜色和单色背景
这应该让你开始,你可能需要稍微调整一下图像框架以使它相对于背景图像正确。
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");
}
}
}
有什么问题......它显示图片,但它是在蓝色框架后面。我需要改变那个框架的背景 – Agzam
不...不是背景,更好说色调。我想保留漂亮的圆角和美丽的边框的漂亮的半透明框架。我只是需要改变颜色 – Agzam
可怜的家伙,我不想今天给你更多坏消息,但透明度,圆角和美丽的边界只是苹果在UIButton和几个UILabels背后的一个平面图像。我编辑了答案以反映你的用例。 – Anuj