Set text Inset for UITextField in iOS swift

Solution:

If you want the textfield text to be like one space after the initial position of textfield from the left side then do the following.

Objective c:

        // placeholder inset
        - (CGRect)textRectForBounds:(CGRect)bounds {
    return CGRectInset(bounds, 10, 10);
    }
    
    // text inset
    - (CGRect)editingRectForBounds:(CGRect)bounds {
    return CGRectInset(bounds, 10, 10);

    }

Swift:


    let inset: CGFloat = 8
    
    // placeholder position
    override func textRect(forBounds bounds: CGRect) -> CGRect {
        return bounds.insetBy(dx: inset, dy: inset)
    }


must be use uitextfield delegate.


Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

store cgpoint in userdefaults iOS swift