Last active
February 27, 2021 22:45
-
-
Save DaisukeNagata/fd31ca57b69a68a899b686110ef869c8 to your computer and use it in GitHub Desktop.
SwiftUIList_CardVersion
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 | |
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() | |
} | |
} |
Author
DaisukeNagata
commented
Oct 17, 2020
•
.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