Nick
Nick

Reputation: 479

Xib and Storyboard

I have two files xib and storyboard. In the xib file there is a custom menu for working with photos (brightness, saturation, etc.). Variable containing a photo is in ViewController. I created an @IBAction for each button in xib. How to transfer a photo to a xib file to work with it?

Toolbar.xib file: enter image description here

Toolbar.swift:

@IBAction func BrightnessButton(_ sender: Any) { // Use custom image from ViewController.swift }

ViewController: var customImage: UIImage?

Upvotes: 1

Views: 88

Answers (1)

dvdblk
dvdblk

Reputation: 2935

This should work. You basically want to create a new UIImage variable inside the Toolbar class which gets set when you select an image inside your ViewController class.

ViewController.swift:

class ViewController: UIViewController {
    ...
    var customImage: UIImage? {
        didSet {
           toolbar.image = customImage
        }
    }
    var toolbar: Toolbar!
    ...
}

Toolbar.swift:

class Toolbar {
   ...
   var image: UIImage?
   ...

   @IBAction func BrightnessButton(_ sender: Any) {
    // Use custom image from ViewController.swift
       guard let currentImage = image else {
           // we didn't set the image yet
           return
       }
       // make changes to your image here
   }
}

Upvotes: 1

Related Questions