【发布时间】:2020-01-22 20:12:52
【问题描述】:
这是我使用 SwiftUI 在我的项目中的 List 项目的代码。
struct ServicesListItem: View {
var title: String
var description: String
var colorHex: String
var imageName: String
var body: some View {
HStack {
Image(imageName)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 50, height: 50)
VStack(alignment: .leading, spacing: 4) {
Text(title)
.font(.system(size: 14, weight: .black, design: .rounded))
.foregroundColor(Color(hex: colorHex))
Text(description)
.font(.system(size: 10, weight: .medium, design: .rounded))
.foregroundColor(Color.gray)
}
.frame(height: 60)
}
}
}
我想将每个 ServicesListItem 的所有元素放在另一个“视图”中,并在所有侧面添加填充,以使每个项目的内容看起来都在凸起的视图中,而不是边到边List 的样子。通过使用 UIView 作为 UITableViewCell 内的父视图,我已经使用 UIKit 轻松完成了这项工作。尚未找到使用 SwiftUI 执行此操作的方法。有可能吗?
【问题讨论】: