Harshil.Chokshi
Harshil.Chokshi

Reputation: 681

Buttons, labels, and TextFields are hidden behind image

I am planning to create the card game 'War' for ios just to get more practice working with Swift and have a problem. I used the main storyboard to create all the interface objects. Here is a screenshot...

enter image description here

So I first added an image view and set the image view size as the viewcontroller's view's size and then added a greenish background image. Then I added the labels, text fields, and button. But when I run the app all I see the green background and none of the interface objects. I am thinking it is because the interface items are behind the green background. But it does not make sense because I added the interface objects after the green background.

Anyone know what the issue is and how to solve it? Thank you

Upvotes: 2

Views: 5387

Answers (4)

Snehil Chouhan
Snehil Chouhan

Reputation: 119

It could be due to Image file format. You may need to change from JPG to PNG. In my case it worked.

Upvotes: -1

NRitH
NRitH

Reputation: 13893

In the view hierarchy, drag your background image to be the first subview of your view. The order of subviews in the tree goes back->front.

Upvotes: 4

Shift72
Shift72

Reputation: 448

To bring something to the front, simply select it in your storyboard. Click on Editor in the top left corner. Go to Arrange --> Send to Front

Here's a picture of the menu: https://i.sstatic.net/0eLRN.jpg

Upvotes: 7

Harshil.Chokshi
Harshil.Chokshi

Reputation: 681

Okay so the problem was that all the interface items were behind the image view background. And I solved the problem my adding all the interface items as a subview of the imageview, like code below.

myImageview.addSubview(myButton)
myImageview.addSubview(myLabel)
myImageview.addSubview(myTextField)

Upvotes: 0

Related Questions