Guest User

Untitled

a guest
Feb 1st, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. // simpan diluar class
  2. extension UITextField{
  3.  
  4. func underline(){
  5. let border = CALayer()
  6. let width = CGFloat(2.0)
  7. border.borderColor = UIColor.lightGray.cgColor
  8. border.frame = CGRect(x: 0, y: self.frame.size.height - width, width: self.frame.size.width, height: self.frame.size.height)
  9. border.borderWidth = width
  10. borderStyle = UITextBorderStyle.none;
  11. self.layer.addSublayer(border)
  12. self.layer.masksToBounds = true
  13. }
  14.  
  15. func paddingLeft(size: CGFloat){
  16. let width = CGFloat(size)
  17. let paddingView = UIView(frame: CGRect(x: 0, y: 0, width: width, height: self.frame.size.height))
  18. leftView = paddingView
  19. leftViewMode = UITextFieldViewMode.always
  20. }
  21.  
  22. }
  23.  
  24. // implementasi di ViewController
  25. @IBOutlet weak var txtUsername: UITextField!
  26. @IBOutlet weak var txtPassword: UITextField!
  27.  
  28. override func viewDidLoad() {
  29. super.viewDidLoad()
  30.  
  31. // configure uitextfield
  32. txtUsername.underline()
  33. txtUsername.paddingLeft(size: 0)
  34. txtPassword.underline()
  35. txtPassword.paddingLeft(size: 0)
  36. txtPassword.isSecureTextEntry = true
  37. }
Add Comment
Please, Sign In to add comment