Skip to content

Instantly share code, notes, and snippets.

@pofat
Created July 28, 2016 08:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pofat/5e54b00603325a10e84aded00179ce68 to your computer and use it in GitHub Desktop.
Save pofat/5e54b00603325a10e84aded00179ce68 to your computer and use it in GitHub Desktop.
Padding for UITextField
MyUITextField: UITextField {
// Whatever you like
let padding = UIEdgeInsets(top: 5, left: 5, bottom: 6, right: 6);
// Paddging for place holder
override func placeholderRectForBounds(bounds: CGRect) -> CGRect {
return UIEdgeInsetsInsetRect(bounds, padding)
}
// Padding for text
override func textRectForBounds(bounds: CGRect) -> CGRect {
return UIEdgeInsetsInsetRect(bounds, padding)
}
// Padding for text in editting mode
override func editingRectForBounds(bounds: CGRect) -> CGRect {
return UIEdgeInsetsInsetRect(bounds, padding)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment