Learn Courses My Dashboard

Image for app isn't loading

When I am putting an image into the assets library and the image resolution is right but the image isn’t showing on the preview. Can anyone please help me

@kiki21a

Welcome to the community.

Post your View code so that we can see what you have tried to do.

Post your code as text rather than a screenshot. Copy the code from your View and paste it in a reply.

To format the code nicely, place 3 back-ticks ``` on the line above your code and 3 back-ticks ``` on the line below your code. The 3 back-ticks must be the ONLY characters on the line. The back-tick character is located on the same keyboard key as the tilde character ~ (which is located below the Esc key). You can also highlight an entire code block and click the </> button on the toolbar to wrap the block for you.

This also makes it easier for anyone assisting as they can copy the code and carry out some testing.

How do I post the code as text? I’m sorry for all the questions, I am new to this

Just copy the text from Xcode by selecting it all with your cursor. Click and drag from the word struct all the way down to the last closing brace } so that it is all selected and then press Command + C (Copy).
Switch back to this code crew forum and create a Reply.

Press the back-tick character on your keyboard 3 times so you have ``` at the beginning of the line. Press the return key to get a new line and then press Command + V (Paste).
On the next line add 3 more back-ticks ``` and then press return to get a new line.
Add any comments or explanatory notes that you need to add then tap on the Reply button to post the message.

"
struct ContentView: View {
var body: some View {
Text(“Welcome to Smilon”)
.padding(/@START_MENU_TOKEN@/.all/@END_MENU_TOKEN@/)
.background(Color.gray)

}

}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
"


"When I try to add the image with xcode it says “birthday(which is the name of image) isn’t found”

@kiki21a
What code are you specifying when trying to add the image?

Using your example code, try this:

struct ContentView: View {
    var body: some View {
        VStack {
            Image("birthday")
                .resizable()
                .aspectRatio(contentMode: .fit)

            Text("Welcome to Smilon")
                .padding()
                .background(Color.gray)
        }
        .padding(.horizontal)
    }
}

I don’t have an image in my assets folder that has 3 different sizes. I just downloaded an image from unsplash.com that was a birthday theme. This is what it looks like on screen in Preview with the above code.

Ok! Thank you, I’ll will try this tomorrow