MacOS上Swiftui的按钮的基线对准
我正在尝试垂直对齐文本
和一个常规按钮
沿MacOS上的Swiftui的基线。我基本上想从WiFi偏好窗格中复制这种布局:
我希望将上述控件放入hstack
,并将对齐设置为。 FirstTextBaseline
将产生此布局。尽管许多其他控件都是这种情况,但它似乎与非平台按钮不起作用。请参见以下示例:
HStack(alignment: .firstTextBaseline) {
Text("Text")
Text("Large Text")
.font(.title)
Button {} label: {
Text("Button")
}
Button {} label: {
Text("Borderless")
}
.buttonStyle(.borderless)
Button {} label: {
Text("Plain")
}
.buttonStyle(.plain)
Toggle("Toggle", isOn: .constant(true))
Picker("Picker", selection: .constant(0)) {
Text("One").tag(0)
Text("Two").tag(1)
Text("Three").tag(2)
}
.pickerStyle(.radioGroup)
}
.padding()
我认为这是错误的吗?是否有一种方法可以像AppKit一样掌握基线,还是我必须手动定位按钮?
I’m trying to vertically align a Text
and a regular Button
along their baselines in SwiftUI on macOS. I basically want to replicate this layout from the WiFi preference pane:
I expected that putting the said controls into an HStack
with the alignment set to .firstTextBaseline
would produce this layout. While this is the case for many other controls, it doesn’t seem to work with non-plain buttons. See the following example:
HStack(alignment: .firstTextBaseline) {
Text("Text")
Text("Large Text")
.font(.title)
Button {} label: {
Text("Button")
}
Button {} label: {
Text("Borderless")
}
.buttonStyle(.borderless)
Button {} label: {
Text("Plain")
}
.buttonStyle(.plain)
Toggle("Toggle", isOn: .constant(true))
Picker("Picker", selection: .constant(0)) {
Text("One").tag(0)
Text("Two").tag(1)
Text("Three").tag(2)
}
.pickerStyle(.radioGroup)
}
.padding()
Am I holding it wrong? Is there a way to levere the baselines just like in AppKit, or do I have to position the button manually?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论