-2

I have UITextField of which I've added an image.

Everything looks good, except that the text starts from zero X-coordinate, but I want it to start after 5 pixels in text field.

Adi
  • 5,089
  • 6
  • 33
  • 47
SaiRam
  • 13
  • 4

4 Answers4

0

put a left view into your text filed as such :

    textField.layer.cornerRadius = 5.0;
    UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, textField.frame.size.height)];
    textField.leftView = paddingView;
    [paddingView release];
    textField.leftViewMode = UITextFieldViewModeAlways;
devluv
  • 2,007
  • 13
  • 13
0

Simple way to do this.

  • Add an image of your textfeld
  • Add an uitextfield with custom type
  • set frame of the added uitextfield & move 5 pixels at right than the image

Checkout attached image for a detailed knowledge

In attached picture you can see gray is an image for the textfield, & inside it I've added textfield 5 px right from gray image with type roundrect, just for the understanding purpose, you have to ake custom type

Enjoy Programming !

Niru Mukund Shah
  • 4,637
  • 2
  • 20
  • 34
0

Simplest Answer :

1) Take one UIImageView. Add that Image for UITextField in UIImageView.

2) Add UITextField with "No Border" above that UIImageView (5 Pixels Right on that UIImageView).

GoodLuck !!!

Bhavin
  • 27,155
  • 11
  • 55
  • 94
0

Try to use this one

  UIImageView *imageView = [[UIImageView alloc] init];

    // add 5 (width) pixel for your space
    imageView.frame = CGRectMake(0,0 ,5, txtFld.frame.size.height);

    txtFld.leftViewMode = UITextFieldViewModeAlways;
    txtFld.leftView = imageView;

And see in this image for more info.

enter image description here

Dharmbir Singh
  • 17,485
  • 5
  • 50
  • 66