1234567891011121314151617181920212223242526272829303132333435363738 |
- import Foundation
- import UIKit
- extension NSMutableAttributedString {
- func setColor(color: UIColor, font: UIFont? = nil, forText stringValue: String) {
- let range: NSRange = self.mutableString.range(of: stringValue, options: .caseInsensitive)
- self.addAttribute(NSAttributedString.Key.foregroundColor, value: color, range: range)
- if let font = font {
- self.addAttribute(NSAttributedString.Key.font, value: font, range: range)
- }
- }
- }
|