Reputation: 4111
This is my first trial on SwiftUI, where I am trying to create a UITable view like UI. I am trying to give fix leading and trailing (not fix width) to cell/views, I have given ample of time and now this is what I have tried with output:
Git : Here is the link to source code to reproduce this issue
Upvotes: 25
Views: 44398
Reputation: 5052
You need to use .padding
modifier for margin. In your code, you have to add padding inside your ScrollView.
{
VStack(alignment: .center){
ForEach(boxes) { box in
BoxViewTable(box: box)
.background(Color.white).padding(EdgeInsets(top: 0, leading: 10, bottom: 0, trailing: 10))
}
After that, inside BoxViewTable, you need to add .frame modifier.
HStack{
Image("\(box.imgUrl)")
.resizable()
.frame(width: 80, height: 100, alignment: .leading)
VStack(alignment:.leading){
Text("\(box.newsTitle)")
.lineLimit(2)
Text("\(box.newsSubTitle) - \(box.dateTime)")
}
}.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .topLeading)
Finally, Don't give up :-)
Upvotes: 39