简体   繁体   中英

How to display label on top of UIImage?

I have been trying to add a label on top of an image but the label is under the image and I've tried turning AutoLayout off, adding constraints and moving tried moving the label on top of and on bottom of the UIImageView in the View controller scene but its still under neither. Anybody know a quick fix? 在此处输入图片说明

Your view hierarchy looks OK (ie the label is further down in the view hierarchy than the image view, meaning that it will appear "over" the image view). If you're not seeing the label, it either doesn't have text in it or the constraints are not defined properly.

I'd suggest running the app through Xcode and then clicking on the "view debugger":

在此处输入图片说明

Then you can examine where precisely the label is (confirming that it is above the image view) and what its frame is (ie perhaps your other constraints are not defined properly) and what text it contains (perhaps it's in the right place but just doesn't have text to show).

You can either navigate through the view hierarchy in the left panel or rotate and expand the wireframe rendition in the main panel.

在此处输入图片说明

I guess that is due to your arrangement of elements and constraints in IB. Try removing all the constraints and see if you have the label on top of the image. If so - add constraints gradually and observe not to launch your label off the screen.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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