像这样,如果你有关于代码的问题请询问,我认为这很容易理解。
import SwiftUI
struct ContentView: View {
var body: some View {
Image(systemName: "person")
.resizable()
.frame(width: UIScreen.main.bounds.height/2, height: UIScreen.main.bounds.height/2)
.aspectRatio(contentMode: .fit)
}
}
Run Code Online (Sandbox Code Playgroud)
更新:用于支持方向更改:
import SwiftUI
struct ContentView: View {
@State var sizeOfImage: CGFloat = UIScreen.main.bounds.height/2
var body: some View {
Image(systemName: "person")
.resizable()
.frame(width: sizeOfImage, height: sizeOfImage)
.aspectRatio(contentMode: .fit)
.onReceive(NotificationCenter.default.publisher(for: UIDevice.orientationDidChangeNotification)) { _ in
sizeOfImage = UIScreen.main.bounds.height/2 }
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7136 次 |
| 最近记录: |