Created
April 16, 2020 08:46
-
-
Save foxicode/cf1e860eafb4572a657ffa9e7b718a6a to your computer and use it in GitHub Desktop.
UITextView subclass with padding
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
| @IBDesignable | |
| class TextViewWithPadding: UITextView { | |
| @IBInspectable var paddingLeft: CGFloat = 0.0 { | |
| didSet { | |
| updateInsets() | |
| } | |
| } | |
| @IBInspectable var paddingRight: CGFloat = 0.0 { | |
| didSet { | |
| updateInsets() | |
| } | |
| } | |
| @IBInspectable var paddingTop: CGFloat = 0.0 { | |
| didSet { | |
| updateInsets() | |
| } | |
| } | |
| @IBInspectable var paddingBottom: CGFloat = 0.0 { | |
| didSet { | |
| updateInsets() | |
| } | |
| } | |
| required init?(coder aDecoder: NSCoder) { | |
| super.init(coder: aDecoder) | |
| updateInsets() | |
| } | |
| func updateInsets() { | |
| textContainerInset = UIEdgeInsets(top: paddingTop, left: paddingLeft, bottom: paddingBottom, right: paddingRight) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment