带有图像的UIActionSheet

iLe*_*ing 2 xamarin.ios uiactionsheet ios

为了上帝的缘故,有人告诉我如何在UIActionSheet上添加图片.

我正在添加它,但不能强制工作表重新拉伸其高度,因此Subview适合.

var sheet = new UIActionSheet ("Sheet with a picture");
sheet.AddButton ("Pick New Picture");

var subView = new UIView(new RectangleF(20,100,280,200)){ 
    BackgroundColor = UIColor.FromPatternImage(Picture)};

sheet.AddSubview(subView);
sheet.AddButton ("Cancel");
sheet.CancelButtonIndex = 1;
Run Code Online (Sandbox Code Playgroud)

我试图改变subView和工作表的contentMode.没工作.我究竟做错了什么? 在此输入图像描述

图片应该适合按钮之间,或者以某种方式通过任何其他方式适合在工作表上

iLe*_*ing 12

我知道这听起来真的很愚蠢,但我找到的最简单的解决方案是添加一些虚拟按钮(以保留空间),然后在它们之上添加准确定义框架坐标的UIImageView.

var sheet = new UIActionSheet ("");
sheet.AddButton ("Discard Picture");
sheet.AddButton ("Pick New Picture");
sheet.AddButton ("Cancel");
sheet.CancelButtonIndex = 2;

// Dummy buttons to preserve the space for the UIImageView
for (int i = 0; i < 4; i++) {
    sheet.AddButton("");
    sheet.Subviews[i+4].Alpha = 0; // And of course it's better to hide them
}

var subView = new UIImageView(Picture);
subView.ContentMode = UIViewContentMode.ScaleAspectFill;
subView.Frame = new RectangleF(23,185,275,210);

// Late Steve Jobs loved rounded corners. Let's have some respect for him
subView.Layer.CornerRadius = 10; 
subView.Layer.MasksToBounds = true;
subView.Layer.BorderColor = UIColor.Black.CGColor;
sheet.AddSubview(subView);
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

  • 像那样.简单.作品.如果有人想要更多控制权,请编写自己的操作表.这并不难,但大多数情况下你的解决方案都足够了. (2认同)