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
You need to use . padding modifier for margin. In your code, you have to add padding inside your ScrollView. After that, inside BoxViewTable, you need to add .
SwiftUI chooses a default amount of padding that's appropriate for the platform and the presentation context. To control the amount of padding independently for each edge, use padding(_:) . To pad all outside edges of a view by a specified amount, use padding(_:) .
SwiftUI lets us set individual padding around views using the padding() modifier, causing views to be placed further away from their neighbors. If you use this with no parameters you'll get system-default padding on all sides, like this: VStack { Text("Using") Text("SwiftUI") .
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 :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With