在HStack{}上调用.relativeSize时,边界不会靠近。表示尺寸没有被调整。
我已经尝试在HStack上重新安排方法调用的顺序,以便在.frame和.border之前和之后调用.relativeSize
struct ContentView : View {
var body: some View{
VStack(alignment: .center, spacing: 1){
//Top box holding a rectangle
HStack{
Text("Test")
}
.frame(width: 355, height: 99, alignment: .center)
.relativeSize(width: 0.95, height: 0.95)
.border(Color.blue, width: 2)
//Bottom box holding 3 recangles
HStack{
Text("Test")
}
.frame(width: 355, height: 47, alignment: .center)
.border(Color.red, width: 1)
}
.frame(width: 355, height: 148, alignment: .center)
.border(Color.black, width: 1)
//body paren
}
}发布于 2019-07-02 00:01:11
只需在文本前后添加一个空格(),并删除.frame()修饰符。这样,HStack将横向扩展到包含VStack的大小的0.95。这是你想要的吗?
struct ContentView : View {
var body: some View{
VStack(alignment: .center, spacing: 1){
//Top box holding a rectangle
HStack{
Spacer()
Text("Test")
Spacer()
}
.relativeSize(width: 0.95, height: 0.95)
.border(Color.blue, width: 2)
//Bottom box holding 3 recangles
HStack{
Text("Test")
}
.frame(width: 355, height: 47, alignment: .center)
.border(Color.red, width: 1)
}
.frame(width: 355, height: 148, alignment: .center)
.border(Color.black, width: 1)
//body paren
}
}https://stackoverflow.com/questions/56603158
复制相似问题