问题描述
我正在关注 Apple 的 WWDC2020 SwiftUI 视频“SwiftUI 的新功能”
这个:https://developer.apple.com/videos/play/wwdc2020/10041/
我已在 Apple 的“Apple Developer”应用程序中打开了此视频,该应用程序提供了演示代码。 我刚刚将这段原始代码复制到 Xcode 中,但它无法正常工作(如下截图),为什么?
原始代码:
struct ContentView: View {
var items: [Item]
var body: some View {
ScrollView {
LazyVGrid(columns: Array(repeating: GridItem(),count: 4)]) {
ForEach(items) { item in
ItemView(item: item)
}
}
.padding()
}
}
}
struct Item: Identifiable {
var name: String
var id = UUID()
var icon: Image {
Image(systemName: name)
}
var color: Color {
colors[colorIndex % (colors.count - 1)]
}
private static var nextColorIndex: Int = 0
private var colorIndex: Int
init(name: String) {
self.name = name
colorIndex = Self.nextColorIndex
Self.nextColorIndex += 1
}
}
struct ItemView: View {
var item: Item
var body: some View {
ZStack {
RoundedRectangle(cornerRadius: 8,style: .continuous)
.fill()
.layoutPriority(1)
.foregroundColor(item.color)
item.icon
.resizable()
.aspectRatio(contentMode: .fit)
.padding(.all,16)
.foregroundColor(.white)
}
.frame(width: 176,height: 110)
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)