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

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

Convert NsNumber, NSDate to String in iOS Swift

Global LocationManager Singleton class iOS Swift