Lis Tahirbegolli
Lis Tahirbegolli

Reputation: 7

How can i set a Padding for the Text in UITextField

I want to put the text in another position but I don't know how to do that? , There is no option to fix this issue on the Attributes Inspector?

See the | needs to be right where the arrow is pointing out:

enter image description here

Upvotes: 0

Views: 829

Answers (1)

Zohair Abbas Hadi
Zohair Abbas Hadi

Reputation: 123

You can make a custom padded TextField. You could try something like this

class PaddedTextFeild: UITextField {
    let padding = UIEdgeInsets(top: 0, left: 15, bottom: 0, right: 5)
    override open func textRect(forBounds bounds: CGRect) -> CGRect {
        return bounds.inset(by: padding)
    }
    override open func placeholderRect(forBounds bounds: CGRect) -> CGRect {
        return bounds.inset(by: padding)
    }
    override open func editingRect(forBounds bounds: CGRect) -> CGRect {
        return bounds.inset(by: padding)
    }
}

You could try using this class as it is. And change the UIEdgeInsets defined in the first line.

Upvotes: 3

Related Questions