Reputation: 6176
is there a way to add inset in an existing UITextField which was created in the storyboard? I added the constraints, an IBOutlet and I use :
fromTF.textRectForBounds(CGRectInset(fromTF.bounds, 50, 0))
But there is not the inset. Is it only possible to add inset if the textfield is created dynamically?
Upvotes: 2
Views: 6770
Reputation: 7275
textRectForBounds:
is a function, not a property, you can't "set" it like you are trying to do. Check the documentation for UITextField.
You should not call this method directly. If you want to customize the drawing rectangle for the text, you can override this method and return a different rectangle.
If you want the appearance of an inset solely through interface builder, do as Adama has said and place a UIView
behind the text field, make the textfield background clear, and set the UIView
's background color such that it looks like it is the background of the textfield.
Upvotes: 1
Reputation: 1097
There might be a way to accomplish what you're trying to do by subclassing the textField. (this might help if you go this route: Text inset for UITextField?)
Alternatively, when I run into this problem, I do a few things in storyboard to give the appearance of text inset:
1.) Set the styling in the attributes inspector for the UITextField so that it doesn't have a border or anything - should just be a clear box that you can tap and enter text in.
2.) Then create a container UIView behind it to the full width that you want your text field area to be.
3.) Decrease the width of your UItextfield and align it to the right edge of your container view so that you have the appropriate amount of space on the left.
4.) Then just add some constraints for your container and your UItextfield.
Upvotes: 5