gpt4 book ai didi

ios - swift 用户界面 : How to Fix leading and trailing with margin 10

转载 作者:行者123 更新时间:2023-11-28 23:27:19 25 4
gpt4 key购买 nike

这是我在 SwiftUI 上的第一次试用,我试图在其中创建一个类似于 UI 的 UITable View 。我正在尝试为单元格/ View 提供固定前导和尾随(不固定宽度),我已经给了足够的时间,现在这是我尝试过的输出: enter image description here

Git:Here is the link to source code to reproduce this issue

最佳答案

您需要使用 .padding 修饰符作为边距。在您的代码中,您必须在 ScrollView 中添加填充。

{
VStack(alignment: .center){
ForEach(boxes) { box in
BoxViewTable(box: box)
.background(Color.white).padding(EdgeInsets(top: 0, leading: 10, bottom: 0, trailing: 10))
}

之后,在 BoxViewTable 内部,您需要添加 .frame 修饰符。

 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)

最后,不要放弃 :-)

关于ios - swift 用户界面 : How to Fix leading and trailing with margin 10,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58245605/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com