一,代码:
//
// ContentView.swift
// helloworld2
//
// Created by liuhongdi on 2026/3/28.
//
import SwiftUI
struct ContentView: View {
let imageUrl = "https://imgs-qn.test.com/ware/slider/1938.png"
var body: some View {
GeometryReader { geometry in
VStack {
Text("屏幕宽度: \(geometry.size.width)").padding()
Text("屏幕高度: \(geometry.size.height)")
AsyncImage(url: URL(string: imageUrl)) { image in
image.resizable().aspectRatio(contentMode: .fit)
} placeholder: {
ProgressView() // 加载中显示的进度指示器
}
.frame(width: geometry.size.width, height: 400) // 设置固定尺寸
.background(Color.gray)
Image(systemName: "heart.fill").resizable() // 使用系统图标名称
.foregroundColor(.red) // 设置图标颜色
.frame(width: 200, height: 200)
}
}
.background(Color.yellow)
}
}
#Preview {
ContentView()
}
二,测试效果:
![image]()