我在我的应用程序中显示一排各种 SF 符号,并希望将它们的大小调整为按钮。然而,由于 SF 符号一开始的大小并不相同,当我将它们全部调整到 44x44 时,有些符号显得太大。我可以根据它们的内容来调整它们的大小,但是我实际上不知道这些符号会是什么,只是它们会被类似地分组,即。一堆形状,一堆箭头等
有没有人对如何正确调整它们的大小有任何建议,而不会让其中一些看起来太大。例如,下图中中间的箭头对我来说看起来太大了。
import SwiftUI
import PlaygroundSupport
struct ContentView: View {
var body: some View {
ZStack {
Color.black
VStack {
HStack {
Image(systemName: "arrow.left")
.font(.title)
.foregroundColor(.white)
.border(Color.white.opacity(0.3))
Image(systemName: "arrow.up.right")
.font(.title)
.foregroundColor(.white)
.border(Color.white.opacity(0.3))
Image(systemName: "arrow.down")
.font(.title)
.foregroundColor(.white)
.border(Color.white.opacity(0.3))
}
HStack {
Image(systemName: "arrow.left")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 44.0, height: 44.0)
.font(.headline)
.foregroundColor(.white)
.border(Color.white.opacity(0.3))
Image(systemName: "arrow.up.right")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 44.0, height: 44.0)
.font(.headline)
.foregroundColor(.white)
.border(Color.white.opacity(0.3))
Image(systemName: "arrow.down")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 44.0, height: 44.0)
.font(.headline)
.foregroundColor(.white)
.border(Color.white.opacity(0.3))
}
}
.padding()
}
}
}
PlaygroundPage.current.setLiveView(ContentView())
使用时fill
内容模式它们看起来相同,所以这可能是合适的(只需将帧大小调整到所需的大小)。
使用 Xcode 12 / iOS 14 进行测试。
HStack {
Image(systemName: "arrow.left")
.resizable()
.aspectRatio(contentMode: .fill) // << here !!
.frame(width: 44.0, height: 44.0)
.font(.headline)
.foregroundColor(.white)
.border(Color.white.opacity(0.3))
Image(systemName: "arrow.up.right")
.resizable()
.aspectRatio(contentMode: .fill) // << here !!
.frame(width: 44.0, height: 44.0)
.font(.headline)
.foregroundColor(.white)
.border(Color.white.opacity(0.3))
Image(systemName: "arrow.down")
.resizable()
.aspectRatio(contentMode: .fill) // << here !!
.frame(width: 44.0, height: 44.0)
.font(.headline)
.foregroundColor(.white)
.border(Color.white.opacity(0.3))
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)