ios 7底部的白线与UITextField
Posted
技术标签:
【中文标题】ios 7底部的白线与UITextField【英文标题】:White line on the bottom on ios 7 with UITextField 【发布时间】:2014-01-06 09:12:44 【问题描述】:我有文本字段,我需要显示光标并隐藏键盘。在 ios 6 和 IOS 5 中看起来不错。但在 IOS 7 中我可以看到底部的小白线。
我的代码是
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];
有人知道如何解决这个问题吗?
【问题讨论】:
【参考方案1】:我认为这是由于键盘视图的高度为 1。 所以如果你换行
UIView* dummyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
到
UIView* dummyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
它会起作用的。
【讨论】:
以上是关于ios 7底部的白线与UITextField的主要内容,如果未能解决你的问题,请参考以下文章