3

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:

enter image description here

How can I add a 1pt view at the top to simulate top line?

jszumski
  • 7,430
  • 11
  • 40
  • 53
new2ios
  • 1,350
  • 2
  • 25
  • 56
  • Is this a custom keyboard or the standard phone pad keyboard type? – rmaddy Apr 29 '15 at 15:28
  • This is standard keyboard in simple app, @rmaddy. I have the same issue in my main app (I only use code for moving entire view so the edited control is not hidden). – new2ios Apr 29 '15 at 15:34
  • Show some relevant code in your question. – rmaddy Apr 29 '15 at 15:36
  • 10x, @rmaddy. Accepted answer works fine for me. – new2ios Apr 30 '15 at 07:56
  • If you need code like that then something else is wrong. – rmaddy Apr 30 '15 at 13:29
  • I don't know @rmandy. To be sure that the problem is not in my code I created new App only with one text field. I check and I see that the upper section of the Numpad keyboard is missing border. I have this type of keyboard before but in that case my background had colour different from white. I suppose that this is the problem. – new2ios Apr 30 '15 at 13:33

3 Answers3

7

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;
}
André Slotta
  • 13,774
  • 2
  • 22
  • 34
1

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?.

Community
  • 1
  • 1
jszumski
  • 7,430
  • 11
  • 40
  • 53
0

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
}
Shan Ye
  • 2,622
  • 19
  • 21