0

I am developing one application.In that i set the text filed border width as 1o base don my requirement.So now the first character of text filed will be hidden by border color.SO please tell me how can i set the cursor staring position for UITextField.

venkat
  • 345
  • 8
  • 21
  • Do you want to add space before the cursor? – Pooja M. Bohora Sep 20 '13 at 06:49
  • Try this out. This will create a padding in your textfield. UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, 50)]; self.textfield.leftView = paddingView; self.textfield.leftViewMode = UITextFieldViewModeAlways; – swathy krishnan Mar 27 '15 at 05:36

2 Answers2

2

Make a subclass of UITextField and use that.

Override these methods in your subclass. They will add space from left side in your textfield.

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

// text reposition
- (CGRect)editingRectForBounds:(CGRect)bounds {
     return CGRectInset(bounds, 10, 0);
}
Salman Zaidi
  • 9,342
  • 12
  • 44
  • 61
2

add UIview with border and add UITextField inside UIView

 UIView *baseView = [[UIView alloc] initWithFrame:CGRectMake(0,0, frame.size.width, frame.size.height)];
        [baseView setBackgroundColor:[UIColor clearColor]];
        [baseView setUserInteractionEnabled:YES];
        [baseView setClipsToBounds:NO];
        baseView.layer.borderColor =[UIColor lightGrayColor].CGColor;// UIColorFromRGB(0Xcccccc).CGColor;
        baseView.layer.borderWidth = 1.0f;
        [self addSubview:baseView];
UITextField* txtField = [[UITextField alloc]initWithFrame:CGRectMake(1, 1, frame.size.width-2,  frame.size.height-2)];
        [txtField setBackgroundColor:[UIColor whiteColor]];
[baseView addSubview:txtField];
NANNAV
  • 4,875
  • 4
  • 32
  • 50