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.
Just add padding to the input like this: . tbsearchbar { padding-top: 10px; color: red; //To add some color. }
We can add padding to a JTextField using the setMargin(Insets s) of JTextComponent class.
Create UITextField Extension like this: extension UITextField{ @IBInspectable var placeHolderColor: UIColor? { get { return self. placeHolderColor } set { self. attributedPlaceholder = NSAttributedString(string:self.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With