Skip to content

Instantly share code, notes, and snippets.

@matoelorriaga
Last active May 27, 2017 01:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matoelorriaga/4f2bcea274a3ad8d03a0affd2fdd3faa to your computer and use it in GitHub Desktop.
Save matoelorriaga/4f2bcea274a3ad8d03a0affd2fdd3faa to your computer and use it in GitHub Desktop.
import UIKit
extension UITextField
{
class func connectFields(fields:[UITextField]) -> Void
{
guard let last = fields.last else {
return
}
for i in 0 ..< fields.count - 1
{
fields[i].returnKeyType = .next
fields[i].addTarget(fields[i + 1], action: #selector(UIResponder.becomeFirstResponder), for: .editingDidEndOnExit)
}
last.returnKeyType = .go
last.addTarget(last, action: #selector(UIResponder.resignFirstResponder), for: .editingDidEndOnExit)
}
func underlined(color: UIColor)
{
let border = CALayer()
let width = CGFloat(2)
border.borderColor = color.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
self.layer.addSublayer(border)
self.layer.masksToBounds = true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment