带有图像的 UIActionSheet
看在上帝的份上,有人告诉我如何在 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.FromPatternImage(Picture)};
sheet.AddSubview(subView);
sheet.AddButton ("Cancel");
sheet.CancelButtonIndex = 1;
我尝试更改子视图和工作表的 contentMode。没用。我做错了什么?
图片应适合按钮之间,或通过任何其他方式以某种方式适合纸张
For God's sake somebody tell me how to add a picture on an UIActionSheet.
I am adding it, but can't force the sheet to restretch its height, so the Subview would fit.
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;
I've tried to change contentMode of subView and the sheet. Didn't work. What am I doing wrong?
Picture should fit between buttons, or fit on the sheet somehow through any other way around
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我知道这听起来很愚蠢,但我发现的最简单的解决方案是添加一些虚拟按钮(以保留空间),然后在它们之上添加精确定义框架坐标的 UIImageView。
I know this sounds really stupid, but the easiest solution I found is to add a few dummy buttons (to preserve space) and then on top of them add the UIImageView accurately defining the frame coordinates.
UIActionSheet 不支持此类型的自定义。您可以子类化 UIActionSheet 并使用默认布局(覆盖layoutSubviews,调用超级实现,然后移动内容)。如果您这样做,并且 Apple 更改了框架实现,则无法保证您的子类能够在未来版本的 iOS 中工作。
另一种选择是找到或实现一个可以完成您想要的操作的替代类。
UIActionSheet doesn't support customization of this type. You can subclass UIActionSheet and muck with the default layout (override layoutSubviews, call the super implementation, then move things around). If you do this, there's no guarantee your sublcass will work in future versions of iOS if Apple changes the framework implementation.
The other alternative is to find or implement an alternative class that does what you want.
实际上,这很简单,您不需要破解:
在调用 showInView (或 showFromTabBar 等)后更改 UIActionSheet 的大小,就像他们在 这个例子。
您可能必须更改框架而不是边界,根据我的经验,如果更改边界,操作表不会移动到正确的位置。
不幸的是,这在 iPad 上不起作用。但在那里你可以使用 UIPopoverController。 (提示:如果您不需要箭头,可以将 UIPopoverArrowDirection 使用 0)。
Actually it is quite easy and you don't need a hack:
Change the size of the UIActionSheet AFTER calling showInView (or showFromTabBar, etc), like they do in this example.
You might have to change the Frame instead of the Bounds, in my experience the action sheet is not moved to the right position if you change the Bounds.
On the iPad this doesn't work unfortunately. But there you can use a UIPopoverController. (Tip: you can use 0 for the UIPopoverArrowDirection if you do not want arrows).
这是 Agzam 的答案,但根据 Marcel W 的建议,针对最新的 objc 进行了刷新,并且没有背景按钮 hack。它更短,可能更干净。
This is Agzam's answer, but refreshed for most recent objc and without the background button hack, as suggested by Marcel W. it is shorter and possibly cleaner.