I'm targeting iOS 16 for my app in which I access the screen height and width using UIScreen.main.bounds.width
and UIScreen.main.bounds.height
so I can draw views based on these two values. I'm assigning these two values to two CGFloat
properties in the view struct as follows:
struct ContentView: View {
var width: CGFloat = UIScreen.main.bounds.width
var height: CGFloat = UIScreen.main.bounds.height
var fontSize: CGFloat
var body: some View {
// draw views here using width and height properties
}
Xcode is showing a warning message saying 'main' will be deprecated in a future version of iOS: use a UIScreen instance found through context instead: i.e, view.window.windowScene.screen
I'm not sure how to apply the answer here to my use case and I don't want to use GeometryReader
since it just messes up the overall layout.
Any suggestions on how to obtain screen width and height in an app targeting iOS 16 and above without using GeometryReader
?