I created a custom keyboard for UITextField consisting of 18 UIButtons. This is a UIView that is set as the inputView text field.
Buttons are created in the initWithFrame: UIView method using code
UIImage* buttonImage =[[UIImage imageNamed:@"keyboard-button-background.png"] stretchableImageWithLeftCapWidth:1.0 topCapHeight:79.0]; UIImage* buttonPressedImage =[[UIImage imageNamed:@"keyboard-button-pressed-background.png"] stretchableImageWithLeftCapWidth:1.0 topCapHeight:79.0]; UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setTitle:title forState:UIControlStateNormal]; [button setBackgroundImage:buttonImage forState:UIControlStateNormal]; [button setBackgroundImage:buttonPressedImage forState:UIControlStateHighlighted]; button.frame = CGRectMake(xPosition, yPosition, buttonWidth, buttonHeight);
After clicking the button, this button is set as enabled = NO . The background stretches perfectly while at least one of the buttons is on. If all buttons are disabled and UITextfield resignsFirstResponder , and then UITextField becomes the first responder again, buttons appear, but the background image is no longer stretched (at least not in the vertical direction, it looks beautiful horizontally).
I'm not sure where to start looking for a solution. I assume that in the way the user keyboard draws subviews, but I'm not sure.
Can this be set by setting the background image to layoutSubviews or drawRect: or something like that? The fact that horizontal stretching works fine makes me wonder if the UIButton frame is wrong because it is drawn.
EDIT The cells in the left corner are just labels, the cells on the right with numbers are UIText fields and have a custom keyboard
What should the keyboard look like: 
What the keyboard actually looks like, once left the first responder to cell 3, then gave 1 first responder (all keys are disabled), and then gave 4 first responders: 
source share