title: Change label text while image in UIScrollview changes
body: <p>I want to create an image gallery similar to this:</p>
  
  <p><a href="http://sweettutos.com/2015/04/13/how-to-make-a-horizontal-paging-uiscrollview-with-auto-layout-in-storyboards-swift/" rel="nofollow noreferrer">http://sweettutos.com/2015/04/13/how-to-make-a-horizontal-paging-uiscrollview-with-auto-layout-in-storyboards-swift/</a></p>
  
  <p>Where each time the user swipes and the image changes and the label title changes.I have written the code and included the <code>if</code> statement, however, it does not work properly and it only changes as one value.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>import UIKit
  
  class ViewController: UIViewController {
  @IBOutlet weak var mainscrollview: UIScrollView!
  var imageArray = [UIImage]()
  
  
      @IBOutlet var label: UILabel!
      override func viewDidLoad() {
          super.viewDidLoad()
          mainscrollview.frame = view.frame
          imageArray = [#imageLiteral(resourceName: "goku"), #imageLiteral(resourceName: "boruto"), #imageLiteral(resourceName: "tail"), #imageLiteral(resourceName: "sage"),#imageLiteral(resourceName: "tobi")]
  
          for i in 0..&lt;imageArray.count{
          let imageView = UIImageView()
              imageView.image = imageArray[i]
              imageView.contentMode = .scaleAspectFit
              let xPosition = self.view.frame.width * CGFloat(i)
  
              imageView.frame = CGRect(x: xPosition, y: 0, width: self.mainscrollview.frame.width,height: self.mainscrollview.frame.height)
              mainscrollview.contentSize.width = mainscrollview.frame.width * CGFloat(i + 1)
              mainscrollview.addSubview(imageView)
  
              let gokuImage = UIImage(named: "goku")
              let borutoImage = UIImage(named: "boruto")
  
              if imageView.image == gokuImage{
  
                  label.text = "Goku"
              }
              if imageView.image == borutoImage{
  
                  label.text = "bor"
              }
          }
      }
  }
  </code></pre>
  
  <p>This is where the project is going wrong:</p>
  
  <pre><code>let gokuImage = UIImage(named: "Goku")
              let borutoImage = UIImage(named: "boruto")
  
              if imageView.image == gokuImage{
  
                  label.text = "Goku"
              }
              if imageView.image == borutoImage{
  
                  label.text = "bor"
              }
  </code></pre>
  
  <p><strong><em>I think this is because the if statement can not directly access the current image that is being displayed in the UIScroll view.</em></strong></p>
  
  <p>Here is the link to my project: <a href="http://www.mediafire.com/file/adkzcpvdtodlyl5/gallery_copy.zip" rel="nofollow noreferrer">http://www.mediafire.com/file/adkzcpvdtodlyl5/gallery_copy.zip</a></p>