title: Swift - Color fill animation
body: <p>I'm relatively new to ios animations and I believe there's something wrong with the approach I took to animate UIView.</p>
  
  <p>I will start with a UI screenshot to picture my problem more precisely:</p>
  
  <p>There is a tableView cell with two labels and colorful filled circle
  <a href="https://i.stack.imgur.com/wi8Vf.png" rel="noreferrer"><img src="https://i.stack.imgur.com/wi8Vf.png" alt="enter image description here"></a></p>
  
  <p>Anytime I introduce new value to the cell, I'd like to animate this left-most bulb so it looks like it's getting filled with red color. </p>
  
  <p>This is the implementation od BadgeView, which is basically the aforementioned leftmost filled circle</p>
  
  <pre><code>class BadgeView: UIView {
  
  var coeff:CGFloat = 0.5
  
  override func drawRect(rect: CGRect) {
      let topRect:CGRect = CGRectMake(0, 0, rect.size.width, rect.size.height*(1.0 - self.coeff))
      UIColor(red: 249.0/255.0, green: 163.0/255.0, blue: 123.0/255.0, alpha: 1.0).setFill()
      UIRectFill(topRect)
  
      let bottomRect:CGRect = CGRectMake(0, rect.size.height*(1-coeff), rect.size.width, rect.size.height*coeff)
      UIColor(red: 252.0/255.0, green: 95.0/255.0, blue: 95.0/255.0, alpha: 1.0).setFill()
      UIRectFill(bottomRect)
              self.layer.cornerRadius = self.frame.height/2.0
      self.layer.masksToBounds = true
     }
  }
  </code></pre>
  
  <p>This is the way I achieve uneven fill - I introduced coefficient which I modify in viewController.</p>
  
  <p>Inside my cellForRowAtIndexPath method I try to animate this shape using custom button with callback</p>
  
  <pre><code>let btn:MGSwipeButton = MGSwipeButton(title: "", icon: img, backgroundColor: nil, insets: ins, callback: {
          (sender: MGSwipeTableCell!) -&gt; Bool in
          print("Convenience callback for swipe buttons!")
          UIView.animateWithDuration(4.0, animations:{ () -&gt; Void in
              cell.pageBadgeView.coeff = 1.0
              let frame:CGRect = cell.pageBadgeView.frame
              cell.pageBadgeView.drawRect(frame)
          })
          return true
          }) 
  </code></pre>
  
  <p>But it does nothing but prints to console</p>
  
  <blockquote>
    <p>: CGContextSetFillColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.</p>
  </blockquote>
  
  <p>Although I'd love to know the right answer and approach, it would be great to know, for education purpose, why this code doesn't work.
  Thanks in advance</p>