ios VStack前导对齐不适用于嵌套文本视图

ia2d9nvy  于 11个月前  发布在  iOS
关注(0)|答案(1)|浏览(164)

我的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)

字符串
效果如下:


的数据
为什么不左对齐?

sc4hvdpw

sc4hvdpw1#

初始化函数上的VStack前导对齐用于对齐所有子视图,.frame函数上的VStack前导对齐用于对齐其父视图。嵌套在内部的两个TextView也是如此。默认情况下,您使用.framealignment = .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
因此,要使文本前导向左对齐,只需:

Text("entry.titleAlert hajdfg dgfhds fghjds gfhjdsg fhjdsg2")
    .frame(maxWidth: .infinity, alignment: .leading)
    ...

字符串

相关问题