简体   繁体   English

使UILabel出现在情节提要中的UIImageView顶部

[英]Make UILabel appear on top of UIImageView in storyboard

I want to make the a label appear over an image view. 我想使标签出现在图像视图上。 But when I place the label over it it disappears. 但是,当我将标签放在上面时,它消失了。 Whats the best way around this? 最好的办法是什么?

I have a couple of labels over my image view. 我在图像视图上有几个标签。 When I build and run it the labels appear fine. 当我构建并运行它时,标签看起来很好。 But on the storyboard when I place ui items such as a label over my image view it doesn't show. 但是在情节提要上,当我在图像视图上放置ui项目(例如标签)时,它不会显示。 How can I make this show 我该如何演出

图片

As seen on the screen shot I can't see my labels It appears when I build and run but on the story board the image view hides it this is still a problem. 从屏幕截图中可以看到,我看不到标签。在构建和运行时会出现,但是在故事板上,图像视图隐藏了它,这仍然是一个问题。

In a story board, if you place the label on top of the image view it will appear that way. 在情节提要中,如果将标签放置在图像视图的顶部,它将以这种方式显示。 Just make sure that you have the proper constraints on both the image view and the label so that they would be on top of each other and it should work. 只需确保在图像视图和标签上都具有适当的约束,以使它们可以彼此叠置并且可以正常工作。 To answer your question, putting a label on top of an image view does not make it disappear. 要回答您的问题,在图像视图的顶部放置标签不会使其消失。

This would put the label in front of the image view: 这会将标签放在图像视图的前面:

这会将标签放在imageview的前面

and this would put it behind the imageview 这会将它放在imageview的后面

这会将它放在imageview的后面

Just replace the order from the side menu in storyboard. 只需替换情节提要中侧面菜单中的命令即可。 Put it below the image view and it will be on top 将其放在图像视图下方,它将位于顶部

The method has been updated since swift 3 该方法已从swift 3更新

What has worked for me and hopefully for you is using : 对我有用并希望对您有用的是使用:

YourView.bringSubview(toFront: yourelementA)
YourView.bringSubview(toFront: yourelementB)

Alternatively you could use the following to send the object that is in the front: 或者,您可以使用以下命令发送位于最前面的对象:

YourView.sendSubview(toBack: yourelementC)

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

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