RoundTextField.swift 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. layer.cornerRadius = 5.0
  31. layer.borderWidth = 1.0
  32. layer.borderColor = #colorLiteral(red: 0.1886746883, green: 0.3115345836, blue: 0.6041364074, alpha: 1)
  33. }
  34. func getText() -> String? {
  35. return self.text
  36. }
  37. }