Ios 使用Xcode中的“下一步”和“上一步”按钮创建图像库
我不熟悉Swift的发展。我上过几门课,但有些问题我找不到 我想设计一个应用程序,有50个或更多的图像,与上一个和下一个按钮,通过他们在一个矩阵 我看过一些随机的示例代码片段,但是我很难弄清楚如何去做。在视图中,在这些图像之间来回移动最简单、最有效的方法是什么?我的另一个问题是,我想能够保存图像时,它被选中 当然,这个问题的答案对你来说很容易,但我是一个初学者,经过两天的搜索和尝试,我找不到解决办法 提前谢谢Ios 使用Xcode中的“下一步”和“上一步”按钮创建图像库,ios,swift,swiftui,Ios,Swift,Swiftui,我不熟悉Swift的发展。我上过几门课,但有些问题我找不到 我想设计一个应用程序,有50个或更多的图像,与上一个和下一个按钮,通过他们在一个矩阵 我看过一些随机的示例代码片段,但是我很难弄清楚如何去做。在视图中,在这些图像之间来回移动最简单、最有效的方法是什么?我的另一个问题是,我想能够保存图像时,它被选中 当然,这个问题的答案对你来说很容易,但我是一个初学者,经过两天的搜索和尝试,我找不到解决办法 提前谢谢 Finotoni您需要执行以下步骤: 获取/定义您的图像 有获取上一幅和下一幅图像的方
Finotoni您需要执行以下步骤:
struct ContentView: View {
// Your images
@State var images = ["image1", "image2", "image3"]
// Some indicator on what image is the current one
@State var imageIndicator: Int = 0
var body: some View {
HStack {
// Prev one
Button(action: {
// Call a method that gets you the previous image
if self.imageIndicator == 0 {
self.imageIndicator = self.images.count - 1
} else {
self.imageIndicator = self.imageIndicator - 1
}
}) {
Image(systemName: "arrow.left")
}
// Image with indicator to what image to display
Image(self.images[self.imageIndicator]).resizable().frame(width: 100, height: 100)
// Next one
Button(action: {
// Call a method that gets you the next image
if self.imageIndicator == self.images.count - 1 {
self.imageIndicator = 0
} else {
self.imageIndicator = self.imageIndicator + 1
}
}) {
Image(systemName: "arrow.right")
}
}
}
}
产生以下结果:
是否要使用iPhone照片库图像?或者这50幅图像将作为资产提供?这将给出一个概述。让我知道它有帮助吗?您可以使用集合视图。然后,当你按下下一步或上一步按钮时,你必须更改索引。。。或者你也可以使用UIPageController谢谢你的回答。我不想使用iPhone照片库。我想使用应用程序中的照片我不想使用UIPageController。我想使用带有两个箭头的图像库,返回和下一个。