Created
August 12, 2020 14:04
-
-
Save kkebo/092c077f9ff0ec3f2d35fd7416469c39 to your computer and use it in GitHub Desktop.
EditButton on a header of a section
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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