【问题标题】:Concatenating two Text Views within an HStack container?在 HStack 容器中连接两个文本视图?
【发布时间】:2019-11-21 01:21:03
【问题描述】:

我想知道是否有人可以为我指出正确的方向,让两个文本项目彼此相邻而不留下白色间隙(见下图)。有很多间距、边框和对齐方式,但玩了 30 分钟后,我似乎没有更近了。

我使用的代码如下:

struct TestView: View {
    var body: some View {
        VStack {
            HStack() {
                Text("SHOT").background(Color.red)
                Text("GUN").background(Color.blue)
            }
            Text("SHOTGUN").background(Color.green)
        }
    }
}

【问题讨论】:

    标签: swiftui hstack


    【解决方案1】:

    试试

    struct ContentView: View {
        var body: some View {
            VStack {
                HStack(spacing: 0) {
                    Text("SHOT").background(Color.red)
                    Text("GUN").background(Color.blue)
                }
                Text("SHOTGUN").background(Color.green)
            }
        }
    }
    

    【讨论】:

    • 将间距设置为零
    • 非常感谢先生,完美。
    猜你喜欢
    • 2019-10-28
    • 2013-01-11
    • 2018-01-14
    • 2018-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-24
    • 2021-01-26
    相关资源
    最近更新 更多