SwiftUI:在 macOS 上调整 ColorPicker 的大小

问题描述

我在我的一个基于 SwiftUI 的 macOS 应用程序中使用了 ColorPicker。在以前版本的 macOS 中,ColorPicker 的行为类似于 ColorSpacer 视图:它填满了所有可用空间。此行为已更改 - 现在似乎具有固定的默认大小:

enter image description here

如何在 macOS (SwiftUI) 上更改 ColorPicker 的大小?

  • .frame() 修饰符无效
  • GeometryReader 内进行调整不走运
  • .resizable() 具有视觉效果,但会产生静态(不可点击)视图

解决方法

如果你想把它变小,你可以使用scaleEffect

ColorPicker("",selection: .constant(.red))
    .scaleEffect(x: 0.5,y: 0.5)

要使边框为方形,请使用 .scaleEffect(x: 0.521739,y: 1)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...