Created
June 27, 2020 19:21
-
-
Save BrayanMC/5295c30236e680175354f2ba91b8ae43 to your computer and use it in GitHub Desktop.
Change part of the text color.
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
func attributedStringWithColor(_ strings: [String], color: UIColor,font : UIFont, characterSpacing: UInt? = nil) -> NSAttributedString { | |
let attributedString = NSMutableAttributedString(string: self) | |
for string in strings { | |
let range = (self as NSString).range(of: string) | |
attributedString.addAttribute(NSAttributedString.Key.foregroundColor, value: color, range: range) | |
attributedString.addAttribute(NSAttributedString.Key.font,value: font, range: range) | |
} | |
guard let characterSpacing = characterSpacing else {return attributedString} | |
attributedString.addAttribute(NSAttributedString.Key.kern, value: characterSpacing, range: NSRange(location: 0, length: attributedString.length)) | |
return attributedString | |
} | |
/* | |
let textTitleNotNetwork: NSAttributedString = "¡Uy! No podemos conectarnos".attributedStringWithColor(["conectarnos"], color: UIColor(hexString: "#EF3340"), font: UIFont(fontStyle: .latoRegular, size: 24)!) | |
lblTitleNotNetwork.attributedText = textTitleNotNetwork | |
/* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment