问题描述
我的 ColorPicker 在 iPad/iPhone 上看起来不错,带有彩色圆圈,但在 macOS 上,颜色是几乎填满屏幕宽度的矩形,但甚至不一致。使用 Xcode 12.4、Swift 5、mac 催化剂,iOS 目标是 14.0。这是图像:
代码就是这样的标准 SwiftUI:
Section(header: Text("Region")) {
ColorPicker("Active region color",selection: Binding(
get: { activeColor },set: { newValue in
activeColorName = newValue.toString
activeColor = newValue
}))
}
有什么方法可以使它看起来像 iOS 设备上的 ColorPicker 一样漂亮?至少消除参差不齐的左边距?差点让我想念 AutoLayout。
编辑:
我最终做了这样的事情:
Section(header: Text("Region")) {
HStack {
Text("Active region color")
Spacer()
ColorPicker("",selection: Binding(
get: { activeColor },set: { newValue in
activeColorName = newValue.toString
activeColor = newValue
}))
.frame(maxWidth: 500)
}
}
但我很惊讶这是必要的,当然这不像你在 iDevice 上看到的那么漂亮。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)