Ben Lu
Ben Lu

Reputation: 3042

Indentation in UITextField

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

UITextView indentation problem:

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

Upvotes: 5

Views: 4218

Answers (3)

Rajesh Loganathan
Rajesh Loganathan

Reputation: 11217

Just try like this simple method....

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

Upvotes: 1

Piyush Kashyap
Piyush Kashyap

Reputation: 1965

Try this

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

Upvotes: 12

Paul.s
Paul.s

Reputation: 38728

Create a subclass and override textRectForBounds: and editingRectForBounds:. Your new implementations may look something like

- (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);
}

Upvotes: 8

Related Questions