Created
December 30, 2021 17:42
-
-
Save StanislavK/eb1e4dd0e2ebff66be80e201ec11b3c2 to your computer and use it in GitHub Desktop.
Single line list row separator (edge to edge).
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 SwiftUI | |
struct Row: View { | |
let text: String | |
let showDivider: Bool | |
var body: some View { | |
VStack(alignment: .leading) { | |
Text(text) | |
.padding(showDivider ? [.leading, .top] : [.leading, .top, .bottom]) | |
if showDivider { | |
Divider().background(Color(UIColor.separator)) | |
} | |
} | |
} | |
} | |
struct ContentView: View { | |
enum Flavor: String, CaseIterable, Identifiable { | |
var id: String { self.rawValue } | |
case vanilla, chocolate, strawberry | |
} | |
var body: some View { | |
List { | |
ForEach(Flavor.allCases, id: \.self) { flavor in | |
Row(text: "\(flavor.rawValue)", showDivider: flavor == Flavor.allCases.last ? false : true) | |
} | |
.listRowSeparator(.hidden) | |
.listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0)) | |
.listRowBackground(Color(UIColor.systemYellow).opacity(0.2)) | |
} | |
.listStyle(InsetGroupedListStyle()) | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This will create the following list with single line style separators: