Skip to content

Instantly share code, notes, and snippets.

@djryanash
Created May 11, 2023 06:04
Show Gist options
  • Save djryanash/c03804499f73019e8a5462eaa7b24a7e to your computer and use it in GitHub Desktop.
Save djryanash/c03804499f73019e8a5462eaa7b24a7e to your computer and use it in GitHub Desktop.
Swift UITextField subclass to add padding.
class UITextFieldPadded: UITextField {
var textPadding = UIEdgeInsets(
top: 5,
left: 10,
bottom: 5,
right: 10)
override func textRect(forBounds bounds: CGRect) -> CGRect {
let rect = super.textRect(forBounds: bounds)
return rect.inset(by: textPadding)
}
override func editingRect(forBounds bounds: CGRect) -> CGRect {
let rect = super.editingRect(forBounds: bounds)
return rect.inset(by: textPadding)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment