UITextField+PlaceholderAttributes.swift 549 B

123456789101112131415161718
  1. //
  2. // UITextField+PlaceholderAttributes.swift
  3. // SwiftTheme
  4. //
  5. // Created by kcramer on 3/6/18.
  6. // Copyright © 2018. All rights reserved.
  7. //
  8. import UIKit
  9. extension UITextField {
  10. @objc func updatePlaceholderAttributes(_ newAttributes: [NSAttributedString.Key: Any]) {
  11. guard let placeholder = self.attributedPlaceholder else { return }
  12. let newString = NSAttributedString(attributedString: placeholder,
  13. merging: newAttributes)
  14. self.attributedPlaceholder = newString
  15. }
  16. }