title: UILabel textColor Extension
body: <p>I want to create an extension for UILabel, I want to modify the UILabel class to automatically check if the text value is positiv/negativ/cero and then set the Color automatically.</p>
  
  <p>I want to activate it when I initialise UILabel in my code like this:</p>
  
  <pre><code>lazy var labelValue: UILabel! = {
          let lb = UILabel()
          lb.activateUpDown = true
          return lb
      }()
  </code></pre>
  
  <p>This is the extension I created:</p>
  
  <pre><code>extension UILabel {
      var activateUpDown: Bool {
          set {
              if activateUpDown == true {
                 textColor = colorUpDown(value: text)
              }
          }
          get {
              return true
          }
      }
  
      func colorUpDown(value: String?) -&gt; UIColor {
          let valueDouble = Double(value ?? "0") ?? 0
          var output:UIColor = .black
          if valueDouble &lt; 0 {
              output = .red
          } else {
              if valueDouble &gt; 0 {
                  output = .green
              } else {
                  output = .black
              }
          }
          return output
      }
  }
  </code></pre>
  
  <p>When I set activateUpDown to true during my initialisation then it does not work.</p>
  
  <p>If I put in updateConstraints it works but this is not where I want it.</p>
  
  <pre><code>override func updateConstraints() {
          if(shouldSetupConstraints) {
              shouldSetupConstraints = false
          }
          super.updateConstraints()
          labelValue.activateUpDown = true
      }
  </code></pre>
  
  <p>Is it possible to create the extension the way I want it or are my thoughts nonsense?</p>
  
  <p>Edit:
  Basically what I want is I want to change the Setter of textColor, if activateUpDown is set to true and somebody sets textColor to a value. It checks if the value is positiv/negativ/zero.</p>
  
  <p>I ended up doing a subclass of UILabel:</p>
  
  <pre><code>import UIKit
  
  class CustomUILabel: UILabel {
  
      var activateUpDown = false
  
  
      var textValue: String? {
          willSet(newValue){
              text = newValue
              if activateUpDown == true {
              textColor = colorUpDown(value: newValue)
              }
          }
      }
  
      func colorUpDown(value: String?) -&gt; UIColor {
          let valueDouble = Double(value ?? "0") ?? 0
          var output:UIColor = .black
          if valueDouble &lt; 0 {
              output = .red
          } else {
              if valueDouble &gt; 0 {
                  output = .green
              } else {
                  output = .black
              }
          }
          return output
      }
  
      required init(coder aDecoder: NSCoder) {
          super.init(coder: aDecoder)!
      }
  
      override init(frame: CGRect) {
          super.init(frame: frame)
      }
  
      /*
      // Only override draw() if you perform custom drawing.
      // An empty implementation adversely affects performance during animation.
      override func draw(_ rect: CGRect) {
          // Drawing code
      }
      */
  
  }
  </code></pre>