Skip to content

Instantly share code, notes, and snippets.

@DaisukeNagata
Last active February 27, 2021 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DaisukeNagata/fd31ca57b69a68a899b686110ef869c8 to your computer and use it in GitHub Desktop.
Save DaisukeNagata/fd31ca57b69a68a899b686110ef869c8 to your computer and use it in GitHub Desktop.
SwiftUIList_CardVersion
import SwiftUI
final class ViewModel: ObservableObject {
@Published var spIndex = [""]
}
struct ContentView: View {
@ObservedObject var viewModel = ViewModel()
init() {
// backcolor
UITableView.appearance().backgroundColor = .clear
self.viewModel.spIndex = ["Apple",
"Pear",
"Orange",
"Cake", "Apple"+"\n"+"Pear"+"\n"+"Orange"+"\n"+"Cake"]
}
var body: some View {
List {
ForEach(self.viewModel.spIndex.indices, id: \.self) { tex in
ListRow(tx: self.viewModel.spIndex[tex])
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
.listRowInsets(EdgeInsets())
.background(Color.white)
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct ListRow: View {
@State var tx: String
var body: some View {
VStack {
Text(tx)
.padding()
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
.background(Color.white)
.cornerRadius(8)
.shadow(radius: 6)
.padding()
}
}
@DaisukeNagata
Copy link
Author

DaisukeNagata commented Oct 17, 2020

スクリーンショット 2020-10-18 6 35 23

@DaisukeNagata
Copy link
Author

.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)

Remus with variable and automatic size.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment