Skip to content

Instantly share code, notes, and snippets.

@Slowhand0309
Last active October 10, 2020 16:54
Show Gist options
  • Save Slowhand0309/0d653b79dae0d4908e978fc18ef4ae34 to your computer and use it in GitHub Desktop.
Save Slowhand0309/0d653b79dae0d4908e978fc18ef4ae34 to your computer and use it in GitHub Desktop.
[Padding UITextField] Add padding to UITextField #iOS
import UIKit
@IBDesignable class UIPaddingTextField: UITextField {
// MARK: Properties
@IBInspectable var padding: CGPoint = CGPoint(x: 8.0, y: 0.0)
// MARK: Internal Methods
override func textRect(forBounds bounds: CGRect) -> CGRect {
return bounds.insetBy(dx: self.padding.x, dy: self.padding.y)
}
override func editingRect(forBounds bounds: CGRect) -> CGRect {
return bounds.insetBy(dx: self.padding.x, dy: self.padding.y)
}
override func placeholderRect(forBounds bounds: CGRect) -> CGRect {
return bounds.insetBy(dx: self.padding.x, dy: self.padding.y)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment