Skip to content

Instantly share code, notes, and snippets.

@phynet
Last active August 9, 2017 07:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phynet/84b9e03941c4890895ac86f72416e63d to your computer and use it in GitHub Desktop.
Save phynet/84b9e03941c4890895ac86f72416e63d to your computer and use it in GitHub Desktop.
Add color to a certain part of a string (or NSString)
func configureTextr() -> NSAttributedString{
let text = "first string"
let aviso = "second string"
let mainText = text! + " " + aviso!
let attributeText = aviso
let range = (mainText as NSString).range(of: attributeText!)
let attributedString = NSMutableAttributedString(string:mainText)
attributedString.addAttribute(NSForegroundColorAttributeName, value: UIColor.rentaliaLightBlue(withAlpha: 1), range: range)
return attributedString
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment