Padding Placeholder text ios

ios, uitextfield

Solution

You could subclass your `UITextFiled` and override methods:

MyTextField.m

- (CGRect)textRectForBounds:(CGRect)bounds {
    return [self rectForBounds:bounds];
}

- (CGRect)editingRectForBounds:(CGRect)bounds {
    return [self rectForBounds:bounds];
}

- (CGRect)placeholderRectForBounds:(CGRect)bounds {
    return [self rectForBounds:bounds];
}

//here 40 - is your x offset
- (CGRect)rectForBounds:(CGRect)bounds {
    return CGRectInset(bounds, 40, 3);
}

upd: also set

textFiled.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

because it could some problems with io6 vs ios 7 vertical positionning

Problem

I want to make the placeholder text display in middle of the textfield (Padding placeholder text). The size of the placeholder text also needs to increase. My code is as follows, how can i solve this ? ``` UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(30, 220,250,55)]; textField.placeholder=@"iiiiiii"; UIView *padView = [[UIView alloc] initWithFrame:CGRectMake(10, 110, 10, 0)]; textField.leftView = padView; textField.leftViewMode = UITextFieldViewModeAlways; [self.view addSubview:textField]; ``` UPDATE I want the font size of the placeholder text to increase `your name`, and it should have a Left padding to it.

Original source

Related problems