简体   繁体   English

SwiftUI/Widget - 为什么 `Date` 的 `Text` 在 HStack 中占用了这么多空间

[英]SwiftUI/Widget - Why the `Text` for `Date` takes so much space in HStack

Why the Text for Date takes so much space.为什么DateText占用这么多空间。

var body: some View {
    VStack{
        HStack(alignment: .top, spacing: 0) {
            VStack{
                Text(entry.date, style:.relative)
            }
            .background(Color.yellow)
            Text("ago")
        }
        
        .font(.system(size: 12))
        .foregroundColor(.gray)
    }.padding()
}

在此处输入图像描述

I would like to display the ago static text right after the dynamic date Text element in HStack我想在 HStack 中的动态日期Text元素之后显示ago的 static 文本

I can simply do this:我可以简单地这样做:

Text("\(entry.date, style: .relative) ago") and there is no need for a HStack Text("\(entry.date, style: .relative) ago")并且不需要HStack

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM