Indentation in a UITextField

For example, I want the "test" text a little bit right, what property should I set?

UITextView indent problem:

For example, I want the text "test" to be slightly correct, which property should I set?

+5
source share
3 answers

Subclass and override textRectForBounds:and editingRectForBounds:. Your new implementations might look something like this:

- (CGRect)textRectForBounds:(CGRect)bounds;
{
    return CGRectInset([super textRectForBounds:bounds], 10.f, 0.f);
}

- (CGRect)editingRectForBounds:(CGRect)bounds;
{
    return CGRectInset([super editingRectForBounds:bounds], 10.f, 0.f);
}
+8
source

try it

    UIView *paddingView           = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 20)];
    self.yourtextField.leftView             = paddingView;
    self.yourtextField.leftViewMode         = UITextFieldViewModeAlways;
+12
source

Just try this simple method ....

textfield.frame = CGRectMake(textfield.frame.origin.x+10, textfield.frame.origin.y, textfield.frame.size.width, textfield.frame.size.height);
+1
source

All Articles