为了上帝的缘故,有人告诉我如何在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;
我试图更改subView和工作表的contentMode。没工作。我究竟做错了什么?
图片应该适合按钮之间,或者通过任何其他方式适合在工作表上
答案 0 :(得分: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);
答案 1 :(得分:2)
UIActionSheet不支持此类型的自定义。你可以使用默认布局子类化UIActionSheet和muck(覆盖layoutSubviews,调用超级实现,然后移动东西)。如果你这样做,那么如果Apple更改了框架实现,则无法保证你的sublcass在iOS的未来版本中有效。
另一种选择是找到或实现一个符合你想要的替代类。
答案 2 :(得分:2)
实际上它非常简单,你不需要黑客攻击:
更改调用showInView(或showFromTabBar等)后的UIActionSheet的大小,就像在this example中一样。
您可能需要更改框架而不是边界,根据我的经验,如果更改边界,操作表不会移动到正确的位置。
在iPad上,这不行。但是你可以使用UIPopoverController。 (提示:如果您不想要箭头,可以使用0作为UIPopoverArrowDirection。)
答案 3 :(得分:1)
这是Agzam的答案,但是对于最近的objc而且没有背景按钮破解,正如Marcel W.所建议的那样,它更短,可能更清洁。
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];