通过编程创建UITextField时向上滚动

问题描述

| 因此,我不完全确定为什么会这样,并尝试通过分配“尝试和错误”来解决问题,并进行了广泛的研究。 不过,我似乎找不到其他遇到过相同问题的人。 我正在尝试以编程方式创建UITextField,并且使用了此代码(我已经编辑了代码以使其更易于理解)
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];
安装到模拟器中时,它会显示并看起来很棒,但是当我选择文本字段时,它将自动向上滚动,直到文本距离包装盒大约一半为止。它可以让我进行编辑,但只能看到一半的文字。 有什么想法吗?或如何解决? 抱歉,这有点令人困惑,很难解释。 谢谢您的帮助! 〜邻近     

解决方法

        我有这个完全相同的问题。我意识到我是在创建UITextView而不是UITextField(duh!):
UITextField *textField = [[UITextView alloc] init];
您可能曾经遇到过同样的问题。     ,        
        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];
使用此代码,它将为您提供完美的结果。     

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...