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

Convert NsNumber, NSDate to String in iOS Swift

Global LocationManager Singleton class iOS Swift

Parse the value from string value iOS swift