SwiftUI Shape Scale Size 这样 HStack 大小不会增加

SwiftUI Shape Scale Size Such that HStack size does not increase

我试图让圆圈适合 HStack,这样 HStack 大小就不会增加。 如何在不指定固定框架的情况下使圆适合?

struct ContentView: View {
    
    var body: some View {
        NavigationView {
            Form {
                HStack {
                    Circle()
                        .fill(Color.red)
                        .aspectRatio(1, contentMode: .fit)
                    Text("Hello")
                }
                HStack {
                    Circle()
                        .fill(Color.blue)
                        .aspectRatio(1, contentMode: .fit)
                    Text("Hello")
                }
            }
        }
    }
}

这是可供选择的各种容器示例。 SwiftUI 将完成所有布局,自动处理旋转和设备分辨率。

struct CirclesView: View {
    var body: some View {
        VStack(spacing: 0) {
            Label("Circles", systemImage: "circle").font(.system(size: 24, weight: .black, design: .rounded)).foregroundColor(.pink)
            HStack {
                Circle()
                    .foregroundColor(.yellow)
                    .frame(width: 32, height: 32)
                Text("This is a yellow circle")
                Spacer()
            }
            Circle()
                .foregroundColor(.orange)
                .shadow(radius: 10)
                .frame(width: 75)
            Divider()
            HStack {
                VStack {
                    Circle().foregroundColor(.blue)
                    Text("Blue").font(.title3)
                    HStack {
                        Circle().foregroundColor(.purple)
                        Text("Purple").font(.caption)
                    }
                }
                .padding()
                .background(Color.yellow)
                ZStack(alignment: Alignment(horizontal: .center, vertical: .center)) {
                    Circle().foregroundColor(.green)
                    Text("Green").foregroundColor(.primary)
                }
            }
        }
    }
}