Created
April 16, 2020 07:14
-
-
Save foxicode/4dd3598cb1788d0030fe644801ff630c to your computer and use it in GitHub Desktop.
UITextField subclass with padding editable in Storyboard
This file contains hidden or 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
| import UIKit | |
| @IBDesignable | |
| class TextFieldWithPadding: UITextField { | |
| @IBInspectable var paddingLeft: CGFloat = 0.0 | |
| @IBInspectable var paddingRight: CGFloat = 0.0 | |
| var padding: UIEdgeInsets { | |
| UIEdgeInsets(top: 0, left: paddingLeft, bottom: 0, right: paddingRight) | |
| } | |
| required init?(coder aDecoder: NSCoder) { | |
| super.init(coder: aDecoder) | |
| } | |
| override func textRect(forBounds bounds: CGRect) -> CGRect { | |
| bounds.inset(by: padding) | |
| } | |
| override func placeholderRect(forBounds bounds: CGRect) -> CGRect { | |
| bounds.inset(by: padding) | |
| } | |
| override func editingRect(forBounds bounds: CGRect) -> CGRect { | |
| bounds.inset(by: padding) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment