ios7 - ios 7 上带有 UITextField 的底部白线

标签 ios7 uitextfield

我有文本字段,我需要显示光标并隐藏键盘。在 IOS 6 和 IOS 5 中看起来不错。但在 IOS 7 中我可以看到底部有一条小白线。<​​/p>

我的代码是

UIScrollView *scrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
[scrollview setDelegate:self];
[self.view addSubview:scrollview];
[self.view bringSubviewToFront:scrollview];
[scrollview setBackgroundColor:[UIColor blackColor]];

scrollview.contentSize = CGSizeMake(768, 1024);


UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 10, 500, 100)];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.autocorrectionType = UITextAutocorrectionTypeNo;
textField.keyboardType = UIKeyboardTypeDefault;
textField.returnKeyType = UIReturnKeyDone;
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
textField.returnKeyType = UIReturnKeyDone;
[textField setUserInteractionEnabled:YES];
[textField setEnabled:YES];
[scrollview addSubview:textField];

// Here I need to show the cursor without showing keyboard
UIView* dummyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
((UITextField*)textField).inputView = dummyView;
[((UITextField*)textField) becomeFirstResponder];

enter image description here

有人想过如何解决这个问题吗?

最佳答案

我认为这是由于键盘 View 的高度为1造成的。 所以如果你改变线路

UIView* dummyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)]; 

UIView* dummyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];

它会起作用。

关于ios7 - ios 7 上带有 UITextField 的底部白线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20946524/

相关文章:

ios - UITextField - 防止用户输入非标准字符(如表情符号)

ios - ios7 上的 UICollectionViewData validateLayoutInRect 断言失败

ios6 - 在iOS7的TableViewCell中不会显示选中标记

ios - 在 layoutSubviews() 内部设置子层的框架使得无法更改它。有什么解决方法吗?

ios - UITableView 单元格中的 UITextField 与 shouldChangeCharactersInRange 行为异常

ios - IQKeyboardManager 在 subview 中不工作

ios - 第一次更改 UITextField 属性 isSecureTextEntry 时键盘闪烁

iOS拦截推送通知

iOS 7 动画 block 未被调用

ios - iOS 7 中 Notes 应用程序的字体效果