简体   繁体   English

向存在于堆栈视图中的图像视图添加按钮

[英]Adding a button to an image view present in a stack view

I am trying to add a button to an image view which lies in a stack view. 我试图将按钮添加到位于堆栈视图中的图像视图。 But whenever I try to add the button after adding the image view, the stack view gets divided into two parts, one housing the button and the other housing the image view. 但是,每当我尝试在添加图像视图之后添加按钮时,堆栈视图都会分为两部分,一个包含按钮,另一个包含图像视图。

I want to add an icon which is an image view, on top which there's a button which one clicked does the needful. 我想添加一个图标,它是图像视图,在其顶部有一个按钮,单击该按钮可以完成必要的操作。

Just add the button to the stackView and use background on that button to set the icon: 只需将按钮添加到stackView并在该按钮上使用背景来设置图标:

button.setBackgroundImage(UIImage(named: "icon"), for: .normal)

Or through storyboards select a button and set it in attributes inspector: 或通过情节提要板选择一个按钮并将其设置在属性检查器中:

使用情节提要板设置按钮的背景图像

代替使用按钮,首先添加一个uiview代替按钮,然后在uiview中添加图像和按钮。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM