Skip to content

Instantly share code, notes, and snippets.

@Morbix
Created June 28, 2017 12:52
Show Gist options
  • Save Morbix/cc8807d21a383d639143acf9cf580138 to your computer and use it in GitHub Desktop.
Save Morbix/cc8807d21a383d639143acf9cf580138 to your computer and use it in GitHub Desktop.
UITextField with multiple lines
extension UITextField {
// Works only if the UITextField don't have the focus and have some text,
// so prefer call this in the didEndEditing event.
func setNumberOfLines(_ numberOfLines: Int, lineBreakMode: NSLineBreakMode) {
self.subviews.forEach { subview in
guard let label = subview as? UILabel else { return }
label.lineBreakMode = lineBreakMode
label.numberOfLines = numberOfLines
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment