Skip to content

Instantly share code, notes, and snippets.

@lawreyios
Last active December 17, 2018 15:39
Show Gist options
  • Save lawreyios/5d13bc80d999634e37401e3bc3e5bd23 to your computer and use it in GitHub Desktop.
Save lawreyios/5d13bc80d999634e37401e3bc3e5bd23 to your computer and use it in GitHub Desktop.
Add padding to UITextField - Swift 3.0
class CustomSearchTextField: UITextField {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func textRect(forBounds bounds: CGRect) -> CGRect {
return UIEdgeInsetsInsetRect(bounds, UIEdgeInsetsMake(0, 15, 0, 15))
}
override func placeholderRect(forBounds bounds: CGRect) -> CGRect {
return UIEdgeInsetsInsetRect(bounds, UIEdgeInsetsMake(0, 15, 0, 15))
}
}
@Laeyoung
Copy link

@lawreyios It doesn't work on edit mode. Can you merge this forked gist (https://gist.github.com/Laeyoung/717002e14dbd97b810569be4ffbf6ed0)

@xieweizhi
Copy link

Need also override editingRect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment