I am trying to do this tutorial on my iPad (don’t have a Mac running Xcode): https://developer.apple.com/tutorials/swiftui/creating-and-combining-views#Create-a-Custom-Image-View
I’m getting stuck at the point where I want to add an image.
I did manage to import an image to my resources (the box behind the plus sign at the top right of the screen). Now when I reference the image’s name in code I don’t get an error but I also don’t get to see the image. When I try to tap-image-to-include-in-the-code I get a little emoji like thing that looks like an image but how is that supposed to work? If I just put it on a line of code I throws the error “build block requires URL to conform to View”
I’m getting stuck at the point where I want to add an image.
I did manage to import an image to my resources (the box behind the plus sign at the top right of the screen). Now when I reference the image’s name in code I don’t get an error but I also don’t get to see the image. When I try to tap-image-to-include-in-the-code I get a little emoji like thing that looks like an image but how is that supposed to work? If I just put it on a line of code I throws the error “build block requires URL to conform to View”
Code Block struct CircleImage: View { var body: some View { VStack(alignment: .center) { Text("image following") fileLiteral(resourceName: "Foto.png") Image("IMG_1249.png") .clipShape(Circle()) .overlay( Circle().stroke(Color.black, lineWidth: 4)) .shadow(radius: 10) } } }
I tested this out on my iPad with playgrounds 3.4, and for me, it also didn't work except that it said that there was a problem and check the code for mistakes. I added resizable and frame modifiers to the Image view which allowed it to load inside the app. For the image, I just added it using the blue plus in the upper right corner of the app.
Code Block Swift Image(uiImage: #imageLiteral(resourceName: "Photo.png")) .resizable() .frame(width: 200, height: 200) .clipShape(Circle())