简体   繁体   中英

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

Why the Text for Date takes so much space.

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

I can simply do this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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