0

Use two TextFields or using label/view in background. Placing TextFields over some view/label/TextFields is not proper development. And placing label or view in left side isn't the proper way either

enter image description here

I didn't think below way is proper way. So i want a better solutions

UILabel * leftView = [[UILabel alloc] initWithFrame:CGRectMake(10,0,7,26)];
leftView.backgroundColor = [UIColor clearColor];

textField.leftView = leftView;

textField.leftViewMode = UITextFieldViewModeAlways;
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

How can we use following to achieve it

// placeholder position
- (CGRect)textRectForBounds:(CGRect)bounds {
     return CGRectInset( bounds , 10 , 10 );
}

// text position
- (CGRect)editingRectForBounds:(CGRect)bounds {
     return CGRectInset( bounds , 10 , 10 );
}

I was able to achieve using . But is there some better way then this

Txt_SecurityAns.layer.sublayerTransform = CATransform3DMakeTranslation(5, 0, 0);
Txt_Email.layer.sublayerTransform = CATransform3DMakeTranslation(5, 0, 0);
Nischal Hada
  • 3,230
  • 3
  • 27
  • 57
  • 3
    Take a look at [Add inset in UITextField](http://stackoverflow.com/questions/2694411/text-inset-for-uitextfield) – Apoorv Apr 23 '15 at 09:00
  • How to use I didn't get it // placeholder position - (CGRect)textRectForBounds:(CGRect)bounds { return CGRectInset( bounds , 10 , 10 ); } // text position - (CGRect)editingRectForBounds:(CGRect)bounds { return CGRectInset( bounds , 10 , 10 ); } – Nischal Hada Apr 23 '15 at 09:12

1 Answers1

1

Set paddingView in UITextField...

UIView * leftView = [[UIView alloc] initWithFrame:CGRectMake(0,0,7,26)];
textField.leftView = leftView;
textField.leftViewMode = UITextFieldViewModeAlways;
Rahul Mayani
  • 3,761
  • 4
  • 25
  • 40
  • i don't want to add label or view etc. I want to achieve it using some programatic work out of TextFields – Nischal Hada Apr 23 '15 at 09:08
  • Refer this url : http://stackoverflow.com/questions/2694411/text-inset-for-uitextfield – Rahul Mayani Apr 23 '15 at 09:09
  • How to use I didn't get it // placeholder position - (CGRect)textRectForBounds:(CGRect)bounds { return CGRectInset( bounds , 10 , 10 ); } // text position - (CGRect)editingRectForBounds:(CGRect)bounds { return CGRectInset( bounds , 10 , 10 ); } – Nischal Hada Apr 23 '15 at 09:13
  • you have a class derived from UITextField & override at least this two methods... – Rahul Mayani Apr 23 '15 at 09:15
  • Refer this url : https://github.com/samsoffes/sstoolkit/blob/master/SSToolkit/SSTextField.h – Rahul Mayani Apr 23 '15 at 09:16
  • Add padding to UITextField is to subclass with an edgeInsets property. You then set the edgeInsets and the UITextField will be drawn accordingly. This will also function correctly with a custom leftView or rightView set. – Rahul Mayani Apr 23 '15 at 09:18
  • Thanks for your help i was able to achieve using Txt_SecurityAns.layer.sublayerTransform = CATransform3DMakeTranslation(5, 0, 0); Txt_Email.layer.sublayerTransform = CATransform3DMakeTranslation(5, 0, 0); – Nischal Hada Apr 23 '15 at 09:23
  • I m unable to post questions coz of negative marking can u help me out to remove negative marking – Nischal Hada May 12 '15 at 11:48