Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

Loading

@daisukenagata
Copy link
Author

daisukenagata commented Oct 17, 2020

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

Remus with variable and automatic size.

Loading

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