Last active
May 27, 2017 01:44
-
-
Save matoelorriaga/4f2bcea274a3ad8d03a0affd2fdd3faa 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
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