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?
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.
Please see the following images as examples:
snapchat story example 1
snapchat story example 2
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.
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