ios - 多个 UIImage View

标签 ios arrays swift uiimageview uiimage

我目前已通过以下方式将图像设置到 UIImageView 中:

art_image.image = UIImage(named:(artworkPin.title!))

其中 art_image 是 ImageView ,artworkPin.title 是指图像的名称。但是,我想将第二个图像添加到 UIImageView(如果存在)我想将其编程为

       art_image.image = UIImage(named:(artworkPin.title + "1")?)

这行得通吗?在这种情况下,我会将第二个图像命名为第一个图像的名称,但末尾带有“1”。示例:如果 Photo1.jpeg 存在,“Photo.jpeg”和“Photo1.jpeg”都会出现在 ImageView 中。

感谢您的帮助。

最佳答案

我自己也遇到过类似的任务。我所做的是,我使用 UIImageView 的框架创建了一个 UIScrollView ,其 contentSize 将是 imageView.frame.size。宽度 * 图片数量

let scrollView = UIScrollView(frame: view.bounds)
view.addSubview(scrollView)

scrollView.contentSize = CGSize(width: scrollView.bounds.size.width * CGFloat(numberOfImages), height: scrollView.bounds.size.height))

for i in 0...<numberOfImages.count-1 {
    let imageView = UIImageView(frame: CGRect(x: scrollView.bounds.size.width * CGFloat(i), y: scrollView.bounds.origin.y, width: scrollView.bounds.size.width, height: scrollView.bounds.size.height))
    imageView.image = UIImage(named: "artwork" + "\(i)")
    scrollView.addSubview(imageView)
}

如果需要,您可以使用计时器将其设置为滚动动画。

scrollView.setContentOffset(scrollPoint, animated: true)

关于ios - 多个 UIImage View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41658841/

相关文章:

c++ - 如何在 iOS Objective-C 中捕获 C++ 异常代码?

iphone - 创建一个分发给有限选定受众的 iOS 应用程序

php - 基于数组键创建动态命名的变量

c++ - 仅使用存储在数组中的字符串中的第一个字母

ios - Swift 中的 sizeWIthAttributes 出奇地慢

ios - 80 年代的 4 月 1 日日期在 iOS 10.0 中无法解析

iphone - AVErrorInvalidVideoComposition = -11841

ios - 单击 float 按钮(ActionButton)直接转到另一个 View Controller (不生成 float 按钮选项)

c - 整数和数组之间的奇怪转换

ios - 如何解决 Cocoa touch 框架中的符号名称冲突