Skip to content

Instantly share code, notes, and snippets.

@foxicode
Created April 16, 2020 08:46
Show Gist options
  • Select an option

  • Save foxicode/cf1e860eafb4572a657ffa9e7b718a6a to your computer and use it in GitHub Desktop.

Select an option

Save foxicode/cf1e860eafb4572a657ffa9e7b718a6a to your computer and use it in GitHub Desktop.
UITextView subclass with padding
@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