How to Set Left/Right Padding in UITEXTFIELD in IOS

There is a common ISSUE (How to Set Left/Right Padding in UITEXTFIELD in IOS ) we always faced while designing a IOS form and that is Padding and Margin of a UIControl.

Either way we faced the same issue whether we use Storyboard or Programmatically we create a form in IOS.

There are multiple ways to align the control
1- Programatically
2- Dragdrop ( Non-Constraint parameters)
3- Using Constraint parameters

But we will highlight few tips here

Create a new file that’s a subclass of UITextField instead of the default NSObject
Add a new method named – (id)initWithCoder:(NSCoder*)coder to set the image

You may have to import #import <QuartzCore/QuartzCore.h>

Add the rightViewRectForBounds method above

In Interface Builder, click on the TextField you would like to subclass and change the class attribute to the name of this new subclass

In Swift 2:

In Swift 3

In Swift 5