I'm trying to make a visionOS window have an opaque image background setting. I have achieved this but the corners never match, they remain sharp and beyond the window shape.
I have used:
import SwiftUI
import RealityKit
import RealityKitContent
@main
struct BackgroundImageApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
.defaultSize(width: 600, height: 400)
}
}
struct ContentView: View {
var body: some View {
VStack {
Text("Hello, VisionOS!")
.font(.largeTitle)
.foregroundStyle(.white)
.padding()
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
//the backgrond image addition
.background(
Image("studio")
.resizable()
.scaledToFill()
.clipped()
.cornerRadius(24)
)
}
}
As well as various versions of Vstack settings.
It did place the image as the background (and playing with the opacity settings worked) but the corners never fitted.
HangarRash
16.7k5 gold badges31 silver badges64 bronze badges
lang-swift
Color.clear, see this answer for details. Ps, the modifier.cornerRadiusis deprecated, use aRoundedRectangleas clip shape instead.clipShapemodifier to the image withContainerRelativeShapemay help