3

Currently I am setting a leftView with an image and I am finding that the image is too close to the text input view (which in this case is the standard UITextField text input view). Is there a way to shift the frame of the text input view slightly so as to increase the distance between it and the leftView?

Andrew Lauer Barinov
  • 5,694
  • 10
  • 59
  • 83

1 Answers1

3

You should be able to modify the frame property for the UIImageView you're assigning to the UITextField's leftView.

For example you might be able to do something like this:

UIImageView *someImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"someImage"]];

// add 5 points to each side of the frame while keeping the same center point
someImageView.frame = CGRectInset(someImageView.frame, -5, 0);

textField.leftViewMode = UITextFieldViewModeAlways;
textField.leftView = someImageView;

Note that you may also need to modify the UIImageView's contentMode property to get the desired effect (e.g. you can use UIViewContentModeLeft to left-align the image or UIViewContentModeCenter to center-align it).

Beltalowda
  • 4,558
  • 2
  • 25
  • 33