Skip to content

Instantly share code, notes, and snippets.

@geek1706
Created January 9, 2019 01:27
Show Gist options
  • Save geek1706/ae1d4505692b536d1a17262f6e287fbc to your computer and use it in GitHub Desktop.
Save geek1706/ae1d4505692b536d1a17262f6e287fbc to your computer and use it in GitHub Desktop.
func setRequired() {
guard var labelText = self.text else { return }
if labelText.range(of: "*") == nil {
labelText = labelText + "*"
}
let range = (labelText as NSString).range(of: "*")
let attributedString = NSMutableAttributedString(string: labelText)
attributedString.addAttributes([.foregroundColor: UIColor.red], range: range)
self.attributedText = attributedString
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment