I want to use .safeAreaInset
like UIScrollView.contentInset, I noticed that Button
does not work in the safe area regions.
(I want to implement like the sticky header UI.)
Other components work fine.
For example, when I switched to .toggleStyle(.button)
, it also does not work either.
I want to show refreshable
under the red border, so I can't use .padding(.top, 400)
.
Am I missing something? Or is this just a bug in SwiftUI? Any help would be greatly appreciated! Thanks!
import SwiftUI
struct ExampleView: View {
@State var count = 0
@State var toggleValue = false
@State var sliderValue = 0.0
@State var pickerValue = "Apple"
var body: some View {
ScrollView {
VStack {
Text("count: \(count)")
Button { // not worked
count += 1
} label: {
Text("button")
.padding(.horizontal)
}
.buttonStyle(.bordered)
Toggle(isOn: $toggleValue) { // worked
Text("\(toggleValue.description)")
}
HStack {
Text("\(Int(sliderValue))")
.frame(width: 60)
Slider(value: $sliderValue, in: 0...100) // worked
}
Picker("picker", selection: $pickerValue) { // worked
ForEach(["Apple", "Banana", "Chocolate"], id: \.self) { text in
Text(text)
.tag(text)
}
}
Spacer(minLength: 1800)
}
.padding()
.frame(maxWidth: .infinity)
}
.safeAreaInset(edge: .top) {
Spacer()
.frame(height: 400)
.frame(maxWidth: .infinity)
.border(.red, width: 4)
}
}
}
struct ExampleView_Previews: PreviewProvider {
static var previews: some View {
ExampleView()
}
}