Padding in UITextfield in both left and right side iOS swift
Problem:
I want to add padding in left and right side of uitextfield.
How to achieve that?
Solution:
extension UITextField {
func setPadding() {
self.setLeftPaddingPoints()
self.setRightPaddingPoints()
}
func setLeftPaddingPoints(_ amount:CGFloat = 5){
let paddingView = UIView(frame: CGRect(x: 0, y: 0, width: amount, height: self.frame.size.height))
self.leftView = paddingView
self.leftViewMode = .always
}
func setRightPaddingPoints(_ amount:CGFloat = 5) {
let paddingView = UIView(frame: CGRect(x: 0, y: 0, width: amount, height: self.frame.size.height))
self.rightView = paddingView
self.rightViewMode = .always
}
}
Then call the functions as like below.
myTF.setPadding()
Comments
Post a Comment