RoundTextField.swift 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //
  2. // RoundTextField.swift
  3. // Sirani
  4. //
  5. // Created by Anhar Solehudin on 26/03/19.
  6. // Copyright © 2019 Anhar Solehudin. All rights reserved.
  7. //
  8. import UIKit
  9. @IBDesignable
  10. class RoundTextField: UITextField {
  11. let padding = UIEdgeInsets(top: 0, left: 16, bottom: 0, right: 16)
  12. override open func textRect(forBounds bounds: CGRect) -> CGRect {
  13. return bounds.inset(by: padding)
  14. }
  15. override open func placeholderRect(forBounds bounds: CGRect) -> CGRect {
  16. return bounds.inset(by: padding)
  17. }
  18. override open func editingRect(forBounds bounds: CGRect) -> CGRect {
  19. return bounds.inset(by: padding)
  20. }
  21. override func prepareForInterfaceBuilder() {
  22. customizeView()
  23. }
  24. override func awakeFromNib() {
  25. super.awakeFromNib()
  26. customizeView()
  27. }
  28. func customizeView() {
  29. backgroundColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
  30. textColor = UIColor(red: 26/255, green: 29/255, blue: 38/255, alpha: 1.0)
  31. tintColor = #colorLiteral(red: 0.1056468859, green: 0.26498940589999997, blue: 0.5374458432, alpha: 1)
  32. layer.cornerRadius = 8.0
  33. layer.borderWidth = 1.0
  34. layer.borderColor = #colorLiteral(red: 0.88, green: 0.90, blue: 0.94, alpha: 1)
  35. }
  36. func getText() -> String? {
  37. return self.text?.trimmingCharacters(in: .whitespacesAndNewlines)
  38. }
  39. }