我希望我的图标图像是屏幕总可用宽度的1/3。我的代码如下:
var body: some View {
GeometryReader { geometry in
Image(systemName: "square.dashed").resizable()
.aspectRatio(contentMode: .fit).frame(maxWidth: geometry.size.width/3)
}
}
当我这样做时,该图标将显示在屏幕的左上方,而不是我想的那样保留在中心。例如,这可以正常工作,但根据屏幕尺寸不是动态的
var body: some View {
Image(systemName: "square.dashed").resizable()
.aspectRatio(contentMode: .fit).frame(maxWidth: 200)
}
这是可能的解决方案(已通过Xcode 12.1 / iOS 14.1测试)
GeometryReader { geometry in
Image(systemName: "square.dashed").resizable()
.aspectRatio(contentMode: .fit).frame(maxWidth: geometry.size.width/3)
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句