title: In IOS Swift, How do you make white text visible over any background like on snapchat stories
body: <p>I am attempting to use Swift in order to put white text over user profile pictures, but these pictures could be of any color. Does anyone know how to do this in Swift?</p>
  
  <p>Snapchat does this in it's stories where it places white text in the top left corner and the text is visible over any background without a noticeable background effect or darkening of the label's background. Please note I am not referring to the transparent label on the regular snapchat pictures, but just on the snapchat stories. </p>
  
  <p>Please see the following images as examples:</p>
  
  <p>snapchat story example 1</p>
  
  <p><img src="https://i.stack.imgur.com/Eb58s.png" alt="enter image description here"></p>
  
  <p>snapchat story example 2</p>
  
  <p><img src="https://i.stack.imgur.com/hqaVK.png" alt="enter image description here"></p>
  
  <p>I have unsuccessfully attempted to do this by creating a label with a black background that has a low alpha and making the label size only surround the characters of the label's text.</p>
  
  <pre><code>    let nameLabel = UILabel()
      nameLabel.text = "userName"
      nameLabel.textColor = UIColor.whiteColor()
      nameLabel.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.2)
      let adjustedNameSize = nameLabel.sizeThatFits(CGSize(width: 0.8*screenWidth, height: 0.1*screenHeight))
      var nameFrame = CGRectMake(0.05*screenWidth,0.05*screenHeight,0.8*screenWidth,0.1*screenHeight)
      nameFrame.size = adjustedNameSize
      nameLabel.frame = nameFrame
      nameLabel.layer.cornerRadius = 15
      nameLabel.clipsToBounds = true
  </code></pre>