【发布时间】:2021-05-10 06:20:50
【问题描述】:
我有一个带有 4 个按钮的 SwiftUI 工具栏,但是我实现的代码不正确,因为在模拟器中更改设备类型时,按钮最终会出现在奇怪的地方。
更糟糕的是,在 iPhone 8 / 8 Plus 上查看时,有 2 个按钮位于窗口的远端。
如何正确地为工具栏按钮应用间距/填充,以便它们在不同的 iOS 设备上保持一致?
谢谢!
// This code spaces the buttons but they change positions depending on the iOS device
ToolbarItem {
HStack {
HStack {
ProfileUploadMediaButton()
}.padding([.trailing], 85)
HStack {
ProfileUsernameButton()
}.padding([.trailing], 84)
HStack {
ProfileLiveButton()
}.padding([.trailing], 6)
HStack {
AccountButton()
}.padding([.trailing], 12)
}
}
})
// I was thinking code like this but all buttons are bunched together on the right-side of // the screen...
ToolbarItem {
HStack {
ProfileUploadMediaButton()
ProfileUsernameButton()
ProfileLiveButton()
AccountButton()
}
}
【问题讨论】:
-
我不确定这一点,但我认为您可以在每个元素之间添加某种间距元素。 (我认为它被称为灵活空间)让我知道它是否有效!
标签: ios user-interface swiftui ios-simulator toolbar