Skip to content

Instantly share code, notes, and snippets.

@kkebo
Created August 12, 2020 14:04
Show Gist options
  • Save kkebo/092c077f9ff0ec3f2d35fd7416469c39 to your computer and use it in GitHub Desktop.
Save kkebo/092c077f9ff0ec3f2d35fd7416469c39 to your computer and use it in GitHub Desktop.
EditButton on a header of a section
import PlaygroundSupport
import SwiftUI
struct ContentView {
@State var rows = ["hoge", "fuga", "piyo"]
}
extension ContentView: View {
var body: some View {
Form {
Section(
// If EditButton is in HStack, it doesn't work.
// See https://stackoverflow.com/a/63339838
header: EditButton()
.frame(maxWidth: .infinity, alignment: .trailing)
.overlay(Text("hoge"), alignment: .leading)
) {
ForEach(self.rows, id: \.self) {
Text($0)
}
.onDelete { indices in
self.rows.remove(atOffsets: indices)
}
}
}
}
}
PlaygroundPage.current.setLiveView(ContentView())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment