UITextField+Extension.swift 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. //
  2. // UITextField+Extension.swift
  3. // o2app
  4. //
  5. // Created by 刘振兴 on 2017/8/28.
  6. // Copyright © 2017年 zone. All rights reserved.
  7. //
  8. import UIKit
  9. extension UITextField {
  10. // MARK: -
  11. class func createTextField(_ leftView:UIView?, _ rightView:UIView?,_ textPrompt:String?) -> UITextField {
  12. let textField = UITextField(frame: .zero)
  13. textField.backgroundColor = .clear
  14. //textField.clearsOnBeginEditing = true
  15. textField.clearButtonMode = .whileEditing
  16. //leftView
  17. if leftView != nil {
  18. textField.leftView = leftView
  19. textField.leftViewMode = .always
  20. }
  21. //rightView
  22. if rightView != nil {
  23. textField.rightView = rightView
  24. textField.rightViewMode = .always
  25. }
  26. textField.defaultTextAttributes = [NSAttributedString.Key.foregroundColor:UIColor.hexInt(0x666666),NSAttributedString.Key.font:UIFont.init(name: "PingFangSC-Regular", size: 15)!]
  27. textField.attributedPlaceholder = NSAttributedString(string: textPrompt!, attributes: [NSAttributedString.Key.foregroundColor:UIColor.hextIntWithAlpha(0x888888,0.4),NSAttributedString.Key.font:UIFont.init(name: "PingFangSC-Regular", size: 13)!])
  28. //bottom line
  29. return textField
  30. }
  31. }