我的VStack是这样定义的:
VStack(alignment: .leading, spacing: 1) {
Text("entry.titleAlert hajdfg dgfhds fghjds gfhjdsg fhjdsg2")
.frame(maxWidth: .infinity)
.multilineTextAlignment(.leading)
.font(.caption)
.padding(5)
.background(Color(uiColor: .alertNews))
Text("entry.contentAlert jhdsg fdhjsgf dhjsgf dhjsgf jdhsgf jdhsgf jdhsgf jdhsgf dhjsgf dhjsgf hdsgfh dghjf gsdhjgf dhjsgf dhjsgf dhjsg fjdhsg fjhdsgf jhdsgf jdhsgf dhjsgf jdhsgfhjdsg fhdsg fgdsjgfdhjs gfjdhsgf hs")
.frame(maxWidth: .infinity)
.multilineTextAlignment(.leading)
.font(.caption)
.opacity(0.7)
.lineLimit(5)
.padding(5)
.background(Color(uiColor: .alertNews))
Spacer()
}
.frame(maxWidth: .infinity, alignment: .leading)
字符串
效果如下:
的数据
为什么不左对齐?
1条答案
按热度按时间sc4hvdpw1#
初始化函数上的VStack前导对齐用于对齐所有子视图,
.frame
函数上的VStack前导对齐用于对齐其父视图。嵌套在内部的两个TextView也是如此。默认情况下,您使用.frame
和alignment = .center
。@inlinable public func frame(minWidth:CGFloat?= nil,idealWidth:CGFloat?= nil,maxWidth:CGFloat?= nil,minHeight:CGFloat?= nil,idealHeight:CGFloat?= nil,maxHeight:CGFloat?= nil,alignment:align = .center)-> some View
因此,要使文本前导向左对齐,只需:
字符串