最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

swift - An image of an iPhone does not appear in Xcode's Preview Run - Stack Overflow

programmeradmin3浏览0评论

I'm trying to develop an iPhone app using Xcode (Ver. 14.2 for Mac OS Monterey since my Mac is a 2017 model)

Here's the thing:

Even though I start from this template by selecting "Creating new project → App", an image of an iPhone does not appear in Preview/ Run. As I know, an iPhone is supposed to be there. But only objects are working without an iPhone frame as follows.

And this is what's happening when I "run" the same code.

  • I see just a small window pops up, whose size cannot be changed.

What's wrong with my Xcode? Please let me know how to make an image of an iPhone appear

FYI, Here is the code

ContentView

import SwiftUI

struct ContentView: View {
    var body: some View {
        VStack {
            Image(systemName: "globe")
                .imageScale(.large)
                .foregroundColor(.accentColor)
            Text("Hello, world!")
        }
        .padding()
    }
}

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

HelloApp

import SwiftUI

@main
struct HelloApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

I'm trying to develop an iPhone app using Xcode (Ver. 14.2 for Mac OS Monterey since my Mac is a 2017 model)

Here's the thing:

Even though I start from this template by selecting "Creating new project → App", an image of an iPhone does not appear in Preview/ Run. As I know, an iPhone is supposed to be there. But only objects are working without an iPhone frame as follows.

And this is what's happening when I "run" the same code.

  • I see just a small window pops up, whose size cannot be changed.

What's wrong with my Xcode? Please let me know how to make an image of an iPhone appear

FYI, Here is the code

ContentView

import SwiftUI

struct ContentView: View {
    var body: some View {
        VStack {
            Image(systemName: "globe")
                .imageScale(.large)
                .foregroundColor(.accentColor)
            Text("Hello, world!")
        }
        .padding()
    }
}

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

HelloApp

import SwiftUI

@main
struct HelloApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}
Share Improve this question asked Feb 17 at 0:54 SpaceTAKASpaceTAKA 1111 silver badge4 bronze badges New contributor SpaceTAKA is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
Add a comment  | 

1 Answer 1

Reset to default 3

Change the target device

At the center top click on “My Mac” and change it to an iPhone.

If an iPhone option isn’t available you need to make sure you have an iPhone as a selected platform in the General tab for the project.

发布评论

评论列表(0)

  1. 暂无评论