我想将图像框架调整为一个正方形,该正方形与 iPhone 屏幕的宽度相同,因此高度值(屏幕宽度)也相同。
以下代码不起作用,因为它为图像提供了与 View 相同的高度。
var body: some View {
Image("someImage")
.resizable()
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .center)
.clipped()
}
最佳答案
您可以为其创建一个 UIScreen
扩展。喜欢:
extension UIScreen{
static let screenWidth = UIScreen.main.bounds.size.width
static let screenHeight = UIScreen.main.bounds.size.height
static let screenSize = UIScreen.main.bounds.size
}
用法:
UIScreen.screenWidth
关于ios - 如何在 SwiftUI 中获取 iPhone 的屏幕宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57727107/