带有UITextField的ios 7底部的白线

时间:2014-01-06 09:12:45

标签: ios7 uitextfield

我有文字字段,我需要显示光标并隐藏键盘。它在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];

enter image description here

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

1 个答案:

答案 0 :(得分:3)

我认为这是由键盘视图引起的,其高度为1。 所以,如果你改变了行

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

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

它会起作用。