SwiftUI Standard way
GeometryReader is the type that gives you all information about the parent view
So you can use GeometryReader like:
var body: some View {
GeometryReader { geometry in
Text("My text view here")
.frame(width: geometry.size.width - 16)
.background(Color.red) // This is just to see how it looks like
}
}
UIKit Aggressive way
You can get it directly from the device:
var body: some View {
Text("My text view here")
.frame(width: UIScreen.main.bounds.width - 16)
.background(Color.red) // This is just to see how it looks like
}
Note that device width is physical and not updating on rotation. Also I haven't experimented with it to see myself, but I have read the UIScreen runs into problems on SplitView.