Created
May 11, 2023 06:04
-
-
Save djryanash/c03804499f73019e8a5462eaa7b24a7e to your computer and use it in GitHub Desktop.
Swift UITextField subclass to add padding.
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
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