我如何在xamarin.forms中添加UIImageView到UIAlertView
本文关键字:添加 UIImageView UIAlertView forms xamarin | 更新日期: 2023-09-27 17:49:49
UIAlertView alert = new UIAlertView () {
Title = alertTitle, Message = alertMessage
};
UIImageView imageview = new UIImageView ();
UIImage img = UIImage.FromFile ("Resources/Default.png");
imageview.Image = img;
alert.AddSubview (imageview);
alert.AddButton (alertPositiveBtnText);
alert.AddButton (alertNegativeBtnText);
alert.Show ();
这是我正在处理的代码。我想在alertbox中显示一个图像作为背景。我已经设置了UIImageView
和UIAlertView
,但图像没有显示。帮我个忙吗?
Guilherme Torres Castro是正确的。7及以后的版本不支持将UIImageView添加为子视图。但是,对于版本7及以上,您可以使用以下命令:
UIAlertView Msg = new UIAlertView()
{
Title = "Title",
Message = "Content"
};
UIImageView uiIV = new UIImageView(UIImage.FromFile("ImgFile.Png"));
Msg.SetValueForKey(uiIV, (NSString)"accessoryView");
Msg.AddButton("OK");
Msg.Show();
据我所知,在IOS 7及以上版本中,不可能在UIAlertView中添加自定义视图。你必须使用自定义组件来模拟警报,Android有一些选项。
我为Xamarin找到了这个库,但是没有对它进行测试。
UIAlertController alert = UIAlertController.Create("Title", "Message Content" , UIAlertControllerStyle.Alert);
UIImageView imageview = new UIImageView();
alert.Add(imageview);