Last active
January 19, 2018 07:02
-
-
Save bangiqi/83590df5e5c5844d03bf3b08282466a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// simpan diluar class | |
extension UITextField{ | |
func underline(){ | |
let border = CALayer() | |
let width = CGFloat(2.0) | |
border.borderColor = UIColor.lightGray.cgColor | |
border.frame = CGRect(x: 0, y: self.frame.size.height - width, width: self.frame.size.width, height: self.frame.size.height) | |
border.borderWidth = width | |
borderStyle = UITextBorderStyle.none; | |
self.layer.addSublayer(border) | |
self.layer.masksToBounds = true | |
} | |
func paddingLeft(size: CGFloat){ | |
let width = CGFloat(size) | |
let paddingView = UIView(frame: CGRect(x: 0, y: 0, width: width, height: self.frame.size.height)) | |
leftView = paddingView | |
leftViewMode = UITextFieldViewMode.always | |
} | |
} | |
// implementasi di ViewController | |
@IBOutlet weak var txtUsername: UITextField! | |
@IBOutlet weak var txtPassword: UITextField! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// configure uitextfield | |
txtUsername.underline() | |
txtUsername.paddingLeft(size: 0) | |
txtPassword.underline() | |
txtPassword.paddingLeft(size: 0) | |
txtPassword.isSecureTextEntry = true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment