Arun_ Arun_ - 4 months ago 21
iOS Question

Text is not properly visible in UITextField

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?


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

if ([[UIApplication sharedApplication]statusBarOrientation] == UIInterfaceOrientationPortrait) {
[self potraitUI];
[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.


Please set the textfield frame

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

I hope it helps you.