gpt4 book ai didi

ios - 对齐指南()不覆盖 subview

转载 作者:行者123 更新时间:2023-12-01 21:30:25 24 4
gpt4 key购买 nike

我最初将我的 subview 与 .top 对齐通过给 alignment: .top给我的 parent HStack .
然后我想让一个 child 在左边( .leading )和另一个 child 在右边( .trailing )。
但是这不起作用,它们都在中心(下面的屏幕截图):

import SwiftUI

struct TestView: View {
var body: some View {
HStack{
Text("First")
.alignmentGuide(.leading) { d in d[.leading] }
Text("Second")
.alignmentGuide(.trailing) { d in d[.trailing] }
}.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .top)
.padding(.top, 50)
}

}
知道为什么吗?
enter image description here

最佳答案

I then want to have one child to the left (.leading) and the other child to the right (.trailing).


它可以以更简单的方式实现
HStack{
Text("First")
Spacer()
Text("Second")
}.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)

关于ios - 对齐指南()不覆盖 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63052458/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com