I would like to inset the text of a UITextField
.
Is this possible?
A good approach to add padding to UITextField is to subclass and add an edgeInsets property. You then set the edgeInsets and the UITextField will be drawn accordingly. This will also function correctly with a custom leftView or rightView set.
An object that displays an editable text area in your interface.
Overriding -textRectForBounds:
will only change the inset of the placeholder text. To change the inset of the editable text, you need to also override -editingRectForBounds:
// placeholder position - (CGRect)textRectForBounds:(CGRect)bounds { return CGRectInset(bounds, 10, 10); } // text position - (CGRect)editingRectForBounds:(CGRect)bounds { return CGRectInset(bounds, 10, 10); }
I was able to do it through:
myTextField.layer.sublayerTransform = CATransform3DMakeTranslation(5, 0, 0);
Of course remember to import QuartzCore and also add the Framework to your project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With