title: How to draw a UILabel with a different blend mode in draw(_ rect: CGRect) in Swift
body: <p>So I have a <code>UILabel</code> that is being drawn on top of a gradient image (that is a <code>UIImageView</code>). It looks sorta like this:</p>
  
  <p><a href="https://i.stack.imgur.com/byOG6.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/byOG6.jpg" alt="enter image description here"></a></p>
  
  <p>I'm trying to change the <code>blendMode</code> of the graphics context in the <code>UILabel</code>'s <code>draw(_ rect: CGRect)</code> function so that it draws the label but blended with the background with a <code>softLight</code> blending mode.</p>
  
  <p>Here is what I want it to look like:</p>
  
  <p><a href="https://i.stack.imgur.com/H3sum.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/H3sum.jpg" alt="enter image description here"></a></p>
  
  <p>Here is the code I have in the <code>draw(_ rect: CGRect)</code> function:</p>
  
  <pre><code>override func draw(_ rect: CGRect) {
      // Drawing code
       if let context = UIGraphicsGetCurrentContext() {
          context.setBlendMode(.softLight)
          self.textColor.set()
          self.drawText(in: rect)
     }
   }
  </code></pre>
  
  <p>This code just renders the top picture and not the blended version. This is not all that I've tried, I've tried so much other things but I just don't understand <code>CGContext</code>'s and the <code>draw</code> function in particular.</p>
  
  <p>Most answers on SO are either in old objective-c and are deprecated/broken or swift and too complicated (use Metal for example). I just want to draw the text in the context I have and set the context's blending mode to soft light. There has to be an easy way!</p>
  
  <p>Any help on how to fix this would be appreciated. Thanks!</p>