我有一个图像,我正在对尺寸进行硬编码,但意识到它不能针对较大尺寸的类别进行缩放。如何设置首选尺寸并让它自动缩放为不同尺寸?
这就是我的代码的样子:
HStack(alignment: .top, spacing: 4) {
Text("Some text")
Button(action: { showAlert = true }) {
Image(systemName: "questionmark.circle.fill")
.resizable()
.frame(width: 12, height: 12)
.foregroundColor(.secondary)
}
}
Run Code Online (Sandbox Code Playgroud)
我还有其他不使用 SF 符号的情况:
Button(action: action) {
Label(
title: {
Text(title)
.foregroundColor(Color(.label))
},
icon: {
Image("twitter")
.resizable()
.frame(width: 24, height: 24)
}
)
}
Run Code Online (Sandbox Code Playgroud)
这是不同尺寸预览时的样子,但在较大尺寸下图像很小。我该如何处理这个问题以实现可访问性?