I am adding a textfield to my view like this:
UITextField* tf_email = [[UITextField alloc] initWithFrame:CGRectMake((320-btnImage1.size.width)/2, 170, 175, 35)];
[tf_email setBackgroundColor:[UIColor clearColor]];
[tf_email setBorderStyle:UITextBorderStyleRoundedRect];
[tf_email setClearButtonMode:UITextFieldViewModeWhileEditing];
[tf_email setReturnKeyType:UIReturnKeyDone];
[tf_email setAutocapitalizationType:UITextAutocapitalizationTypeNone];
[tf_email setEnablesReturnKeyAutomatically:NO];
[tf_email setDelegate:self];
[tf_email setOpaque:YES];
tf_email.tag=1;
tf_email.font = TTSTYLEVAR(font);
tf_email.layer.cornerRadius = 10;
tf_email.keyboardType = UIKeyboardTypeEmailAddress;
[tf_email setAutocorrectionType:UITextAutocorrectionTypeNo];
tf_email.placeholder = @"[email protected]";
[self.view addSubview:tf_email];
When I enter long text in to this field, the text and the clear button overlaps. Does any one know how to fix this?
Create a subclass of UITextField
and override the methods given below,
/*< Place holder position >*/
- (CGRect)textRectForBounds:(CGRect)bounds {
bounds.size.width = bounds.size.width - 20.0f;
return bounds;
}
/*< Text Posiotion >*/
- (CGRect)editingRectForBounds:(CGRect)bounds {
bounds.size.width = bounds.size.width - 20.0f;
return bounds;
}
Cheers !!!
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