Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Padding Placeholder text ios

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

enter image description here

I want the font size of the placeholder text to increase your name, and it should have a Left padding to it.

like image 234
Sharon Watinsan Avatar asked Dec 06 '13 13:12

Sharon Watinsan


People also ask

How to add padding in placeholder?

Just add padding to the input like this: . tbsearchbar { padding-top: 10px; color: red; //To add some color. }

How do I add padding to textfield?

We can add padding to a JTextField using the setMargin(Insets s) of JTextComponent class.

How do I change the placeholder color in UITextField in IOS Swift?

Create UITextField Extension like this: extension UITextField{ @IBInspectable var placeHolderColor: UIColor? { get { return self. placeHolderColor } set { self. attributedPlaceholder = NSAttributedString(string:self.


1 Answers

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

like image 80
Evgeniy S Avatar answered Oct 06 '22 19:10

Evgeniy S