Skip to content

Instantly share code, notes, and snippets.

@mimthath4
Last active August 12, 2022 14:02
Show Gist options
  • Save mimthath4/4f37773f1f471bdf767ae151685414d3 to your computer and use it in GitHub Desktop.
Save mimthath4/4f37773f1f471bdf767ae151685414d3 to your computer and use it in GitHub Desktop.
import SwiftUI
struct SplitView: View {
@State var selected: Int? = nil
var body: some View {
HStack {
List(0...10, id: \.self, selection: $selected) { number in
HStack {
Text("Select \(number)")
Spacer()
}
.background((selected == number ? highlightColor : nil).offset(x: -10, y: 0))
.contentShape(Rectangle())
.onTapGesture {
selected = number
}
}
.frame(width: 200)
.listStyle(SidebarListStyle())
Spacer()
detailView
Spacer()
}
}
@ViewBuilder var detailView: some View {
if selected == nil {
Text("Nothing is selected")
} else {
Text("\(selected!) is selected")
}
}
var highlightColor: some View {
Color.accentColor
.opacity(0.8)
.cornerRadius(10)
.frame(height: 40)
.frame(minWidth: 150, maxWidth: 200)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment