Skip to content

Instantly share code, notes, and snippets.

@eonil
Created January 9, 2020 10:27
Show Gist options
  • Save eonil/eb0eeaeef7a266ae5aa5a2e0e2a02aa3 to your computer and use it in GitHub Desktop.
Save eonil/eb0eeaeef7a266ae5aa5a2e0e2a02aa3 to your computer and use it in GitHub Desktop.
Single Selection SwiftUI List
//
// ContentView.swift
// SwiftUIWithNSWindowWithoutTitlebar1
//
// Created by Henry Hathaway on 1/9/20.
// Copyright © 2020 Eonil. All rights reserved.
//
import SwiftUI
struct ContentView: View {
@State var selection = Int?.none
var body: some View {
List(selection: $selection) {
ForEach(0..<128) { _ in
makeRow(isSelected: false)
.listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
}
}
}
}
private func makeRow(isSelected:Bool) -> some View {
HStack() {
Rectangle()
.aspectRatio(1, contentMode: .fit)
Text("name")
.font(Font.system(size: NSFont.systemFontSize(for: .small)))
.opacity(0.5)
Text("summary")
.font(Font.system(size: NSFont.systemFontSize(for: .small)))
Spacer()
}
}
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