Search code examples
iosswiftstoryboarduitextfieldinsets

add inset to textfield created in storyboard?


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?


Solution

  • 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.