如何在 SwiftUI 中 create/use \.Identifier?
How to create/use \.Identifier at SwiftUI?
我已经使用 pod 创建分页滚动:
https://github.com/fermoya/SwiftUIPager
但是,有些错误没有描述清楚。
我创建了
struct ContentView: View {
@State private var page = 0
...
}
self.levels = ["img1", "img2"...]
3.
struct cardView: View {
var item : String
@Binding var page: Int
let screenW = UIScreen.main.bounds.width
let screenH = UIScreen.main.bounds.height
let sceneButtonH = UIScreen.main.bounds.height * 0.6494
let sceneButtonW = (UIScreen.main.bounds.height * 0.6494) * 1.0867
let buttonPadding = ((UIScreen.main.bounds.height * 0.6494) * 1.0867) * 0.26
var body: some View{
Button(action: {
//self.showingDetail.toggle()
}) {
Image(uiImage: UIImage(named: item )!)
.renderingMode(.original)
.resizable()
.aspectRatio(contentMode: .fit)
.padding(.leading, buttonPadding/2)
.padding(.trailing, buttonPadding/2)
}
}
}
如何创建.identifier?是自定义方法吗?
根据您的代码,假设 self.level
是 [String]
。如果是,请尝试使用 id: \.self
谢谢!
我已经使用 pod 创建分页滚动:
https://github.com/fermoya/SwiftUIPager
但是,有些错误没有描述清楚。
我创建了
struct ContentView: View { @State private var page = 0 ... }
self.levels = ["img1", "img2"...]
3.
struct cardView: View { var item : String @Binding var page: Int let screenW = UIScreen.main.bounds.width let screenH = UIScreen.main.bounds.height let sceneButtonH = UIScreen.main.bounds.height * 0.6494 let sceneButtonW = (UIScreen.main.bounds.height * 0.6494) * 1.0867 let buttonPadding = ((UIScreen.main.bounds.height * 0.6494) * 1.0867) * 0.26 var body: some View{ Button(action: { //self.showingDetail.toggle() }) { Image(uiImage: UIImage(named: item )!) .renderingMode(.original) .resizable() .aspectRatio(contentMode: .fit) .padding(.leading, buttonPadding/2) .padding(.trailing, buttonPadding/2) } } }
如何创建.identifier?是自定义方法吗?
根据您的代码,假设 self.level
是 [String]
。如果是,请尝试使用 id: \.self
谢谢!