在 iOS 上匹配父母的宽度有效,但在 Mac OS (SwiftUI) 上不起作用 [英] Matching parent's width on iOS works but doesn't work on Mac OS (SwiftUI)
本文介绍了在 iOS 上匹配父母的宽度有效,但在 Mac OS (SwiftUI) 上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在 HStack 中拉伸视图.问题是在 iOS 上运行的相同代码在 Mac OS 上不起作用,我找不到任何合乎逻辑的原因.我错过了什么吗?
I'm trying to stretch a view inside a HStack. The problem is the same code that works on iOS does not work on Mac OS and I can't find any logical reason. Am I missing something?
HStack(spacing: 0) {
Button("A") {
}
Button(action: {}) {
Text("HELLO")
.frame(maxWidth: .infinity)
.padding()
.background(Color.red)
}
Button("B") {
}
}.padding()
Mac os 输出不拉伸按钮
在 iOS 上运行的相同代码
推荐答案
使用 .buttonStyle(PlainButtonStyle())
和 fixedSize()
(optioanl fixedSize())
Use .buttonStyle(PlainButtonStyle())
and fixedSize()
(optioanl fixedSize())
Button(action: {}) {
Text("HELLO")
.frame(maxWidth: .infinity)
.padding()
.background(Color.red)
.fixedSize()
}
.buttonStyle(PlainButtonStyle())
这篇关于在 iOS 上匹配父母的宽度有效,但在 Mac OS (SwiftUI) 上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文