title: Button's background color switches to default color iOS Swift
body: <p>So, I have a simple view with a label and a button. I choose the initial design for these items in storyboard (let's call it default). A label represents a selected file name whereas the button's design changes accordingly. The initial view with colours chosen in storyboard is: <a href="https://i.stack.imgur.com/Kpgqw.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Kpgqw.jpg" alt="enter image description here" /></a></p>
  <p>When I press on the button when the file hasn't been selected yet and Label is nil, everything is okay and the button's color doesn't switch to the default.</p>
  <p>Here is how the view looks like when I pressed &quot;Select file&quot; and canceled the DocumentPickerView: <a href="https://i.stack.imgur.com/fb2jM.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fb2jM.jpg" alt="enter image description here" /></a></p>
  <p><strong>And here is when the wrong stuff begins.</strong> When I press on &quot;Select file&quot; and cancel the touch, the button's background color switches back to the default one I chose in storyboard, but the title color remains the same. Here is a visual representation:</p>
  <p><a href="https://i.stack.imgur.com/graz0.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/graz0.jpg" alt="enter image description here" /></a></p>
  <p>Then I press on &quot;Select file&quot; and do actually select a file. My label changes to the file name and the button changes its design according to a selected file. Like so:</p>
  <p><a href="https://i.stack.imgur.com/gtDiO.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gtDiO.jpg" alt="enter image description here" /></a></p>
  <p>But again, the moment I press on the &quot;Change file&quot; and cancel the touch, the button's background color switches to default. <strong>Even if I don't cancel the touch</strong>, press on &quot;Change file&quot; and do select a file, when the DocumentPickerView is being gone, I see the button's default background color for a second at least. So, as you see, the title color remains the one I made programmatically, but the background still switches.</p>
  <p><a href="https://i.stack.imgur.com/LKTGC.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LKTGC.jpg" alt="enter image description here" /></a></p>
  <p>Please, see my code:</p>
  <pre><code>import UIKit
  import MobileCoreServices
  
  @available(iOS 13.0, *)
  class ViewController: UIViewController {
      
      @IBOutlet weak var fileNameLabel: UILabel!
      @IBOutlet weak var selectButton: RoundedButton!
          
      var _fileURL: URL? = nil {
          didSet {
              changeSelectButtonDesign(isFileURLNil: _fileURL == nil)
          }
      }
      
      @IBAction func selectButtonAction(_ sender: Any) {
          let importMenu = UIDocumentPickerViewController(documentTypes: String(kUTTypeArchive)], in: .open )
          importMenu.delegate = self
          importMenu.modalPresentationStyle = .formSheet
          self.present(importMenu, animated: true, completion: nil)
      }
      
      func changeSelectButtonDesign(isFileURLNil: Bool) {
          if isFileURLNil {
              selectButton.setTitle(&quot;Select file&quot;, for: .normal)
              selectButton.backgroundColor = .blue
              selectButton.setTitleColor(.orange, for: .normal)
              selectButton.highlightedColor = .brown
          } else {
              selectButton.setTitle(&quot;Change file&quot;, for: .normal)
              selectButton.backgroundColor = .red
              selectButton.setTitleColor(.black, for: .normal)
              selectButton.highlightedColor = .clear
          }
      }
      
      override func viewDidLoad() {
          super.viewDidLoad()
      }
  }
  
  
  @available(iOS 13.0, *)
  extension ViewController: UIDocumentPickerDelegate {
      func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
          if let fileURL = urls.first, fileURL.pathExtension == &quot;zip&quot; {
              self._fileURL = fileURL
              self.fileNameLabel.text = _fileURL?.lastPathComponent
          } else {
              _fileURL = nil
              fileNameLabel.text = nil
          }
      }
      
      func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {}
      
      func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) {
         changeSelectButtonDesign(isFileURLNil: _fileURL == nil)
      }
  }
  
  </code></pre>
  <p>What I have tried:
  Experimenting with function that changes the design, changing default colours, making different design for .touchCanceled, .touchUpInside.
  I have also tried making default colours in <code>Attributes Inspector</code>, but the problem remains.</p>
  <p>What interesting: I've tried linking .touchDragOutside sent event as well as .touchUpInside and adding a target to a button and a selector. The first one works as I need it to. Although, pressing the button that way is not what I need in my project.
  <strong>How can I solve it <strong>WITHOUT</strong> increasing complexity of what I have?</strong> - This is very important because that's a test project and the real project I am working on is more complex.</p>
  <p>Thank you!</p>