0
UITextField *theLastNameTF = [[UITextField alloc]init];
theLastNameTF.borderStyle = UITextBorderStyleNone;
theLastNameTF.font = [UIFont fontWithName:@"Helvetica-neue"  size:24.0];
theLastNameTF.textColor = [UIColor grayColor];
theLastNameTF.textAlignment = NSTextAlignmentLeft;
[theScrollView addSubview:theLastNameTF];

I'm creating a textfield using the above code.I need to show a line under the textfield,so i'm adding a gray coloured UILabel to text field.

-(void)addLineToTextField:(UITextField *)theTextfield
{
    UILabel *theSeparatorLine = [[UILabel alloc]initWithFrame:CGRectMake(0, theTextfield.frame.size.height-0.5, theTextfield.frame.size.width, 0.5)];
    theSeparatorLine.frame = CGRectIntegral(theSeparatorLine.frame);
    theSeparatorLine.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    theSeparatorLine.backgroundColor = kCS_LightGrayColor;
    [theTextfield addSubview:theSeparatorLine];

    theSeparatorLine = nil;
}

I'm facing a issue in textfield,while entering texts,the text are half visible and cursor is not moving towards left of text.

Please refer the image,I have entered "arun... arun 123",as expected the cursor should be at left of 123,but the cursor is not moving further.

enter image description here

How can i fix this this?

EDIT

This code is to reframe the UI (call layoutViewForCurrentorientation () inside orientation change method)

-(void)layoutViewForCurrentorientation
{
    if ([[UIApplication sharedApplication]statusBarOrientation] == UIInterfaceOrientationPortrait) {
        [self potraitUI];
    }
    else
    {
        [self landscapeUI];
    }
}

If i remove the line textField.font = [UIFont fontWithName:@"Helvetica-neue" size:24.0]; .I issue is resolved but i need bigger font in textfield.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Arun_
  • 1,806
  • 2
  • 20
  • 40

4 Answers4

3

I was using font [UIFont fontWithName:@"Helvetica-neue" size:24.0] and the textfield size was 25.I made my UITextfield height to 30 and the issue got resolved.Don't know the actual reason but it worked.

Arun_
  • 1,806
  • 2
  • 20
  • 40
1

Please set the textfield frame

UITextField *theLastNameTF = [[UITextField alloc]initWithFrame:CGRectMake(50,50,250,30)];

I hope it helps you.

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

I'm seeing the same problem in 9.3. Appears to be an iOS bug.

When the UITextField is first responder, the UITextField contains a scrollview (UIFieldEditor) which contains the input view (a _UIFieldEditorContentView, -[UITextField inputView].) The bug is that the input view is the incorrect size. The input view is not wide enough and thus the scrollview's -contentSize is also incorrect. The UITextField is scrolling as far right as it can, but that's not far enough because the input view is too small.

My workaround is to reset the text field's text. You'll also probably need a flag to ignore delegate callbacks:

_ignoreTextDelegate = TRUE;

NSString *text = textField.text;
textField.text = nil;
textField.text = text;

_ignoreTextDelegate = FALSE;
0

Try this

UITextField *theLastNameTF = [[UITextField alloc]initWithFrame:CGRectMake(20,50,250,30)];
theLastNameTF.borderStyle = UITextBorderStyleNone;
theLastNameTF.font = [UIFont fontWithName:kHelveticaneue size:15.0];
theLastNameTF.textColor = [UIColor grayColor];
theLastNameTF.textAlignment = NSTextAlignmentLeft;
[theScrollView addSubview:theLastNameTF];

And set the line frame's y value should be with respect to textField frame's y value

-(void)addLineToTextField:(UITextField *)theTextfield
{
    UILabel *theSeparatorLine = [[UILabel alloc]initWithFrame:CGRectMake(0, theTextfield.frame.origin.y + 0.5, theTextfield.frame.size.width, 0.5)];
    theSeparatorLine.frame = CGRectIntegral(theSeparatorLine.frame);
    theSeparatorLine.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    theSeparatorLine.backgroundColor = kCS_LightGrayColor;
    [theTextfield addSubview:theSeparatorLine];

    theSeparatorLine = nil;
}
Suhail kalathil
  • 2,673
  • 1
  • 13
  • 12