user635064
user635064

Reputation: 6247

UIkeyboard popup with uitextfield on top (pic included)

I am trying to achieve this type of effect where a barbutton is pressed and uikeyboard pops up and right above it brings a uitextfield with it. Please see image attached. Can someone point me to the right about how I can do this? Thanks.

enter image description here

Upvotes: 2

Views: 2534

Answers (1)

Legolas
Legolas

Reputation: 12325

  1. Use UIToolbar or UIActionSheet

  2. Setup a textField as an inputAccessoryView for the keyboard.

    UIToolbar* keyboardDoneButtonView = [[UIToolbar alloc] init];
    keyboardDoneButtonView.barStyle = UIBarStyleBlack;
    keyboardDoneButtonView.translucent = YES;
    keyboardDoneButtonView.tintColor = nil;
    [keyboardDoneButtonView sizeToFit];
    UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(30, 10, 260, 30)];
    [keyboardDoneButtonView setItems:[NSArray arrayWithObjects:textField, nil]];
    
    masterTextField.inputAccessoryView = keyboardDoneButtonView;
    
    // where masterTextField is the textField is the one you tap, and the keyboard rises up along with the small textField.
    
    masterTextField.returnKeyType = UIReturnKeyDone;
    
    [masterTextField setKeyboardType:UIKeyboardTypeDefault];
    

update:

For a button, put the above code in the (IBAction) of the button. And instead of masterTextField, create a UIView and add it as a SubView to your view.

Upvotes: 2

Related Questions