Proximity software
Proximity software

Reputation: 11

UITextField scrolls up when created programmatically

So I am not completely sure why this is happening and have tried allot of "trial and error" to fix it, along with some extensive research. Still, I can not seem to find any one else who has encountered this same problem. I am trying to create a UITextField programmatically and I use this code (I have edited the code to make it slightly more understandable)

CGRect textViewFrame = CGRectMake (350, 190, 300, 5000);

UITextView *myTextView = [[UITextView alloc] initWithFrame: textViewFrame];
myTextView.backgroundColor = [UIColor clearColor];
myTextView.text = @"Enter text";
myTextView.font = [UIFont fontWithName: @"Marker Felt" size: 25];

it shows up and look great when installed into the simulator, but when I select the textfield it automatically scrolls up until the text is about half way out of the box. It will let me edit but I can only see half of the text. Any ideas of whats going on? or how to fix it? im sorry that it is a bit confusing, its hard to explain. thank you for your help!

~ Proximity

Upvotes: 1

Views: 215

Answers (2)

Anshuman
Anshuman

Reputation: 25

        CGRect frame = CGRectMake(<your textfield location>);
        UITextField *search= [[UITextField alloc] initWithFrame:frame];
        search.borderStyle = UITextBorderStyleRoundedRect;
        search.textColor = [UIColor blackColor];
        search.font = [UIFont systemFontOfSize:17.0];
        search.placeholder = @"Text";
        search.backgroundColor = [UIColor clearColor];
        search.autocorrectionType = UITextAutocorrectionTypeNo;
        search.keyboardType = UIKeyboardTypeDefault;
        search.returnKeyType = UIReturnKeySearch;
        search.clearButtonMode = UITextFieldViewModeWhileEditing;
        [window addSubview:search];

Use this code it will give you perfect result.

Upvotes: 0

Quentamia
Quentamia

Reputation: 3292

I had this exact same problem. I realized I was creating a UITextView instead of a UITextField (duh!):

UITextField *textField = [[UITextView alloc] init];

You might have been experiencing the same problem.

Upvotes: 1

Related Questions