title: Swift create a common extension for UIButton and UIView Color change
body: <p>In my case, I am trying to creating multiple <code>buttons</code>. Here, each buttons placed on separate UIView. This buttons working like a single section based on selection Its title color and <code>UIView</code> color I am changing in each button acton method. Here, I need to create a common extension for all button title and UIView color change. Once, button click need to pass the value to extension or a function to change the colors for <code>selection</code> button. This is I am trying for reducing the code duplication and LOC.</p>
  
  <p><code>NOTE:</code> Below I posted only one button code but I have many button. I want to make it common class and pass the value to change the colors. How to achieve this?</p>
  
  <p><strong>First Button Action</strong></p>
  
  <pre><code> @IBAction func firstButtonClick(_ sender: Any) {
          self.onetimeView.backgroundColor =  colorLiteral(red: 0.184337255, green: 0.683529412, blue: 0.976475882, alpha: 1)
          self.dailyView.backgroundColor =  colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
          self.weeklyView.backgroundColor =  colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
          self.fiftydaysView.backgroundColor =  colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
          self.monthlyView.backgroundColor =  colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
  
          self.onetimeButton.setTitleColor(UIColor.selectedColor, for: .normal)
          self.dailyButton.setTitleColor(UIColor.disabledColor, for: .normal)
          self.weeklyButton.setTitleColor(UIColor.disabledColor, for: .normal)
          self.fiftydaysButton.setTitleColor(UIColor.disabledColor, for: .normal)
          self.monthlyButton.setTitleColor(UIColor.disabledColor, for: .normal)
      }
  
  @IBAction func secondButtonClick(_ sender: Any) {
         self.onetimeView.backgroundColor =  colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
         self.dailyView.backgroundColor =  colorLiteral(red: 0.184337255, green: 0.683529412, blue: 0.976475882, alpha: 1)
         self.weeklyView.backgroundColor =  colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
         self.fiftydaysView.backgroundColor =  colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
         self.monthlyView.backgroundColor =  colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
  
         self.onetimeButton.setTitleColor(UIColor.disabledColor, for: .normal)
         self.dailyButton.setTitleColor(UIColor.selectedColor, for: .normal)
         self.weeklyButton.setTitleColor(UIColor.disabledColor, for: .normal)
         self.fiftydaysButton.setTitleColor(UIColor.disabledColor, for: .normal)
         self.monthlyButton.setTitleColor(UIColor.disabledColor, for: .normal)
      }
  
  extension UIColor {
      static var selectedColor = UIColor.init(red: 47/255, green: 174/255, blue: 248/255, alpha: 1)
      static var disabledColor = UIColor.init(red: 170/255, green: 170/255, blue: 170/255, alpha: 1)
  }
  </code></pre>