vishwas parashar vishwas parashar - 1 year ago 85
iOS Question

Adding space in UITextField After image

enter image description here

My problem is that I have created a textfield which has leftviewmode as an image and the placeholder is in somewhere middle of textfield where the text editing should get start when user starts typing. So how to get my text started from middle of textfield just where the placeholder is. I cannot set the leftviewmode in imageview because I already added image there. What should I do?

UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"a_point30"]];
image.frame = CGRectMake(0, 0, image.image.size.width, image.image.size.height-10);
self.enterSource.leftViewMode = UITextFieldViewModeAlways; self.enterSource.leftView = image;

For example textediting should began from hello world placeholder.

Answer Source

You can do something like this,

 UIImageView *imgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:imgName]];
imgView.frame = CGRectMake(0.0, 0.0, dropDown.image.size.width+10.0, dropDown.image.size.height);
imgView.contentMode = UIViewContentModeLeft;
textField.leftView = imgView;
textField.leftViewMode = UITextFieldViewModeAlways;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download