Skip to content

Instantly share code, notes, and snippets.

@StanislavK
Created September 1, 2017 09:55
Show Gist options
  • Save StanislavK/38583aa591b00e9729487de89b6ac596 to your computer and use it in GitHub Desktop.
Save StanislavK/38583aa591b00e9729487de89b6ac596 to your computer and use it in GitHub Desktop.
class CustomTextFieldWithPadding: UITextField {
let padding: CGFloat = 16
private var paddingEdgeInsets: UIEdgeInsets {
return UIEdgeInsetsMake(0, padding, 0, padding)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func textRect(forBounds bounds: CGRect) -> CGRect {
return UIEdgeInsetsInsetRect(bounds, paddingEdgeInsets)
}
override func editingRect(forBounds bounds: CGRect) -> CGRect {
return UIEdgeInsetsInsetRect(bounds, paddingEdgeInsets)
}
override func placeholderRect(forBounds bounds: CGRect) -> CGRect {
return UIEdgeInsetsInsetRect(bounds, paddingEdgeInsets)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment