I currently have a TextField
( MaterialComponents.MaterialTextFields
) with a background like the following image:
When writing it looks like this
What I need is to put a padding or filling so that it is not so stuck to the left,
My box is of type textField Materials
@IBOutlet weak var txtPassword: TextField!
func setupStyles(){
self.txtPassword.textColor = Utils.Color.COLOR_A0856A
self.txtPassword.dividerNormalColor = Utils.Color.COLOR_A0856A
self.txtPassword.dividerActiveColor = Utils.Color.COLOR_A0856A
self.txtPassword.attributedPlaceholder =
NSAttributedString(string: NSLocalizedString("strTxtPassword",comment:""), attributes: [NSAttributedStringKey.foregroundColor : UIColor(red:0.74, green:0.78, blue:0.83, alpha:1.0)])
}
I use Swift 4
With TextField and material I mean this
using Shadros solution
self.strPhoneTxt.setLeftPaddingPoints(5)
generates me:
If I change to
self.strPhoneTxt.setLeftPaddingPoints(2)
Unsuccessfully
To do a padding I enclose an extension of the TextField and its way of using it:
And to use it:
I hope it's what you want.
You can try this, for example:
With which the following result is obtained:
You can also use a function instead of setting
didSet
it and something like:and then you call that,
viewDidLoadpor
example, like this:Another way is:
A custom way to add padding to side:
"left"
,"right"
or"both"
inUITextField
.Step 1 - Add this UITextfield extension
Step 2: How to use