我试图在手机应用程序上建立eBay系统列表,但我不知道他们是如何在Rectangle个应用程序中插入图片的.带有圆形矩形修改器的剪辑形状不能提供矩形形状和纵横比...请给我建议.

我只是想不通怎么做,花了2个小时,没有喜悦.

Xcode screenshot with preview

ScrollView {
            
            VStack {
                
                Divider()
                   
                
                HStack {
                    
                    VStack (alignment: .leading) {
                        
                        Rectangle()
                            .scaledToFit()
                            .frame(width: 180)
                            .clipShape(RoundedRectangle(cornerRadius: 15, style: /*@START_MENU_TOKEN@*/.continuous/*@END_MENU_TOKEN@*/), style: /*@START_MENU_TOKEN@*/FillStyle()/*@END_MENU_TOKEN@*/)
                    }
                    
                    
                    Spacer()
                    
                    VStack(alignment: .leading) {
                        Text("Iveco Daily 2.3 XLWB Automatic with Penumatic suspension")
                            .font(.title3)
                        Text("Pre-owned")
                            .font(.footnote)
                            .fontWeight(.semibold)
                            .padding(.bottom)
                        Text("£9,400.00")
                            .fontWeight(.bold)
                        Text("London")
                            .font(.subheadline)
                            .fontWeight(.semibold)
                            .foregroundStyle(.gray)
                    }
                    .padding(.bottom)
                    .padding(.top)
                }
                .padding(.horizontal, 2)
                
                Divider()
                    
            }
        }
        .contentMargins(5)

推荐答案

如果你想要一个图像,然后替换Rectangle()Image(image).resizable()

下面是我的完整测试代码,用于显示剪切到RoundedRectangle的图像,就像该矩形一样:

struct ContentView: View {
    let image = "globe" // <--- for testing
    
    var body: some View {
        ScrollView {
            VStack {
                Divider()
                HStack {
                    VStack(alignment: .leading) {
                        Image(systemName: image) // <--- for testing
                            .resizable()
                            .scaledToFit()
                            .frame(width: 180)
                            .background(Color.cyan)
                            .clipShape(RoundedRectangle(cornerRadius: 15, style: .continuous))
                    }
                    Spacer()
                    VStack(alignment: .leading) {
                        Text("Iveco Daily 2.3 XLWB Automatic with Penumatic suspension")
                            .font(.title3)
                        Text("Pre-owned")
                            .font(.footnote)
                            .fontWeight(.semibold)
                            .padding(.bottom)
                        Text("£9,400.00")
                            .fontWeight(.bold)
                        Text("London")
                            .font(.subheadline)
                            .fontWeight(.semibold)
                            .foregroundStyle(.gray)
                    }
                    .padding(.bottom)
                    .padding(.top)
                }
                .padding(.horizontal, 2)
                Divider()
            }
        }
        .padding(.horizontal, 10)
    }
}

Swift相关问答推荐

如何将新事例添加到枚举中?

为什么我不能在这个 Swift 间接枚举中返回 self ?

如何根据 DatePicker 中选定的日期实现 TabView 页面切换?

如何在设备(或常量)地址空间中创建缓冲区?

防止带有背景的文本扩展到 maxWidth

我怎样才能缩短(提高效率)这段代码?

为 SwiftUI 中的属性提供默认值

如何使用 Swinject 注册符合 ObservableObject 的协议?

`let case(value)` 和 `case(let value)` 之间的区别 (Swift)

试图同时实现两个混合过渡

临时添加到视图层次 struct 后,Weak view引用不会被释放

使用 Alamofire 4.0 (Swift 3) 下载文件

FCM 后台通知在 iOS 中不起作用

在 iOS 中使用 Swift 保存 PDF 文件并显示它们

在 Swift 中将计时器标签格式化为小时:分钟:秒

如何使用 swift 将 Images.xcassets 中的图像加载到 UIImage 中

使用 JSONEncoder 对类型为 Codable 的变量进行编码

使用 swift IOS 使 UIBarButtonItem 消失

如何在swift中的每N个字符处为字符串添加分隔符?

Swift 5 秒后关闭 UIAlertView