I have a view in which I show Numeric Keyboard. My problem is that the keyboard is missing a top line. With a white background an unpleasant effect appears:
How can I add a 1pt view at the top to simulate top line?
I have a view in which I show Numeric Keyboard. My problem is that the keyboard is missing a top line. With a white background an unpleasant effect appears:
How can I add a 1pt view at the top to simulate top line?
quick and dirty:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
UIView *separatorView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth([UIScreen mainScreen].bounds), 1.0 / [UIScreen mainScreen].scale)];
separatorView.backgroundColor = [UIColor lightGrayColor];
textField.inputAccessoryView = separatorView;
return YES;
}
The easiest way would be to add a 1pt tall UIView
as the inputAccessoryView
to a UITextField
. See Custom Views for Data Input.
If you are using more than one field or would rather have more control over it, you can add a subview to your current controller's view
and position it appropriately. To do that you use the keyboard notifications posted by the OS (UIKeyboardWillShowNotification
and UIKeyboardWillHideNotification
), as described in How to make a UITextField move up when keyboard is present?.
For Swift 3, iOS 10
func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
var separatorView = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 1.0/UIScreen.main.scale))
separatorView.backgroundColor = UIColor.lightGray
textField.inputAccessoryView = separatorView
return true
}