UIScreen.main.bounds.width Is deprecated

1.8k Views Asked by At

in SwiftUI,my var has UIScreen.main.bounds.width.

@State private var buttonWidth: Double = UIScreen.main.bounds.width.

UIScreen.main.bounds.width Is deprecated. (main is deprecated) how can i solve?

thank you

1

There are 1 best solutions below

1
Jason On BEST ANSWER

Add the .frame() modifier to your button in your view and let it occupy the screen width infinitely

var body: some View {
    YourButtonClass()
    .frame(maxWidth: .infinity)
}   

Here's documentation on the frame modifier