UITextfield set padding on left and right iOS swift
Solution:
You can use the below extension function to set the padding for textfield in both right and left side.
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
}
}
Comments
Post a Comment