如何在UIAlertController中设置背景颜色



我正在尝试设置UIAlertController的背景色。我使用的代码似乎(几乎(做到了这一点,只是它看起来更像Tint而不是BackgroundColor。角落是我设置的颜色,但警报的主体看起来更像是有色的。我的理解是,实际的警报视图是UIAlertController的最后一个子视图。

我的代码:

var okAlertController = UIAlertController.Create(message, messagetype, UIAlertControllerStyle.Alert);
okAlertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));
int lastView = okAlertController.View.Subviews.Length - 1;
if (messagetype.ToUpper() == "ERROR")
{ 
okAlertController.View.Subviews[lastView].BackgroundColor = new UIColor(CoreImage.CIColor.RedColor );
} 
else if (messagetype.ToUpper() == "SUCCESS") 
{
okAlertController.View.Subviews[lastView].BackgroundColor = new UIColor(CoreImage.CIColor.GreenColor);
}

这是正确的吗?根据我显示的消息类型,我正在寻找一个纯绿色、红色或默认值,或者这是我唯一能做的事情吗?

在我的测试之后,我找到了用代码实现它的方法

okAlertController.View.Subviews[0].Subviews[0].Subviews[0].BackgroundColor=UIColor.Green;

最新更新