Ios 带图像的UIActionSheet

Ios 带图像的UIActionSheet,ios,xamarin.ios,uiactionsheet,Ios,Xamarin.ios,Uiactionsheet,看在上帝的份上,有人告诉我如何在一张纸上加一张图片 我正在添加它,但无法强制图纸重新绘制其高度,因此子视图将适合 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.FromPatte

看在上帝的份上,有人告诉我如何在一张纸上加一张图片

我正在添加它,但无法强制图纸重新绘制其高度,因此子视图将适合

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;
我已尝试更改子视图和工作表的内容模式。没用。我做错了什么?


图片应适合按钮之间,或通过任何其他方式适合工作表。

UIActionSheet不支持此类型的自定义。您可以使用默认布局将UIActionSheet和muck子类化(覆盖LayoutSubView,调用超级实现,然后四处移动)。如果你这么做了,如果苹果改变了框架的实现,你的Subcas将不能保证在未来版本的iOS中工作


另一种方法是找到或实现一个可以实现您想要的功能的替代类。

我知道这听起来很愚蠢,但我找到的最简单的解决方案是添加几个虚拟按钮(以保留空间),然后在其上添加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);
var表=新的UIActionSheet(“”);
sheet.AddButton(“放弃图片”);
sheet.AddButton(“选择新图片”);
sheet.AddButton(“取消”);
sheet.CancelButtonIndex=2;
//保留UIImageView空间的虚拟按钮
对于(int i=0;i<4;i++){
页。添加按钮(“”);
sheet.subview[i+4].Alpha=0;//当然最好隐藏它们
}
var子视图=新UIImageView(图片);
subView.ContentMode=UIViewContentMode.ScaleSpectFill;
框架=新矩形F(23185275210);
//已故的史蒂夫·乔布斯喜欢圆角。让我们尊重他吧
子视图.Layer.CornerRadius=10;
subView.Layer.MasksToBounds=true;
subView.Layer.BorderColor=UIColor.Black.CGColor;
sheet.AddSubview(子视图);

实际上这很简单,你不需要黑客:

在调用showInView(或showFromTabBar等)后更改UIActionSheet的大小,就像在中一样

您可能必须更改帧而不是边界,根据我的经验,如果更改边界,操作表不会移动到正确的位置


不幸的是,在iPad上,这不起作用。但是在那里你可以使用超控器。(提示:如果您不需要箭头,可以使用0表示UIPopoverArrowDirection)。

这是Agzam的答案,但根据Marcel W的建议,对于最新的objc更新,并且没有背景按钮hack。它更短,可能更干净

 UIActionSheet *actionSheet = [[UIActionSheet alloc] init];
  actionSheet.actionSheetStyle = UIActionSheetStyleAutomatic;
  actionSheet.title = @"some text";//here type your information text
  actionSheet.delegate = self;

  [actionSheet addButtonWithTitle:@"Button 1"];
  [actionSheet addButtonWithTitle:@"Button 2"];
  [actionSheet setCancelButtonIndex:1];

//it is up to you how you show it, I like the tabbar
  [actionSheet showFromTabBar:self.tabBarController.tabBar];

//here lays the trick - you change the size after you've called show 
  [actionSheet setBounds:CGRectMake(0,0,320, 480)];

//now create and add your image
   UIImageView *subView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"exampleimage.png"]];
   subView.ContentMode = UIViewContentModeScaleAspectFit;
   subView.Frame = CGRectMake(0,130,320,180);//adjust these, so that your text fits in
   [actionSheet addSubview: (subView)];
   [subView release];

  [actionSheet release];    

你试过这种方法吗?使用ImageView?@Jason它添加了图片视图,但结果是一样的,它不会拉伸视图的高度。你的意思是不支持什么?我可以添加子视图,为什么不能固定工作表的高度?UIActionSheet已内置布局按钮行为。除公共框架中提供的功能外,您无权访问该功能,也无权访问UIActionSheet的任何子视图。您所能做的就是添加子视图,然后按照我的建议覆盖这些实现,尝试在事后修改默认行为。好的。。如何:我可以添加一个带有图像的按钮,一个非标准高度的按钮吗?我想我可以添加几个“虚拟”按钮(保留空间),然后在它们的顶部添加我的子视图,这会产生错觉。按钮将隐藏在ImageView下。。。但我想这将是一种糟糕的方式,而不是那样,我会尝试覆盖layoutSubview。您必须浏览UIActionSheet中的所有子视图,尝试找到按钮并将其向上移动,以便为imageView腾出空间。您可能还需要调整UIActionSheet的框架。如果您发现一些发布的代码可以做类似的事情,我不会感到惊讶,对不起,我不知道有什么可以告诉您。就像这样。简单。作品如果有人想要更多的控制,写下你自己的行动表。这并不难,但你的解决方案在大多数情况下都是足够的。这是一种黑客行为——但这并不是一件坏事,因为备选方案无论如何都会是更复杂的黑客行为(也就是说,将来有同样的机会破译)。您应该将您的问题标记为已回答,以便其他人在查看类似问题时可以找到您的解决方案。