Created
April 2, 2019 11:41
-
-
Save TramPamPam/33db00475282894f6e72a96e1f6623c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private func highlight(_ substring: String, in string: String, color: UIColor = UIColor(named: "Blue")!) -> NSAttributedString { | |
let defaultAttributes = [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 14.0), | |
NSAttributedString.Key.foregroundColor: UIColor.white] | |
let text = NSMutableAttributedString(string: string, attributes: defaultAttributes) | |
if let fillableRange = string.nsRange(of: substring) { | |
text.addAttribute(NSAttributedString.Key.font, value: UIFont.boldSystemFont(ofSize: 14.0), range: fillableRange) | |
text.addAttribute(NSAttributedString.Key.underlineColor, value: color, range: fillableRange) | |
text.addAttribute(NSAttributedString.Key.underlineStyle, value: 1, range: fillableRange) | |
} | |
return text | |
// fillableLabel.attributedText = text | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment