Search code examples
iosobjective-cuitextfielduipickerviewactionsheetpicker

Drop down menu on UITextField?


In my current view I have 7 different text fields. 1 of them has a UIPicker as its input by doing : self.pickerTextField.inputView = _thePicker;

My problem is this: For now all the text fields look the same, I have tried changing their configurations, and even adding a small arrow pointing down to the one with the Picker but it does not give me the look I am looking for.

This is what I have now:

enter image description here

& This is the "menu/ drop down" look that I am looking for: enter image description here

Like I said, I have tried adding arrow images and it just does't have that 3D look like the bottom picture does. Thanks for your help!

Edit: My question is not about the AccesoryView to add prev/ next/ done buttons. My question is about changing the actual TextField's appearance.


Solution

  • I have done what you are trying to do and used ActionSheetPicker. I extended it and added an ActionSheetMultiPicker, but it sounds like the single component would work for you.

    This works really well and results in a nice ActionSheet style picker that is presented from the bottom.

    Also, I used the following to set a current property that I then resigned first responder in the method that instantiated the ActionSheetPicker.

    - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
        curTextUIObject = textField;
        return YES;
    }
    

    I then wired up the editingDidBegin to an IBAction for presenting the ASPicker:

    - (IBAction)relationshipPickerButtonPressed:(id)sender {
        [curTextUIObject resignFirstResponder];
    
         [ActionSheetStringPicker showPickerWithTitle:@"Select Relationship"
                                                 rows:self.relationshipsArray
                                     initialSelection:self.selectedRelationshipIndex
                                               target:self
                                        successAction:@selector(relationshipWasSelected:element:)
                                         cancelAction:@selector(actionPickerCancelled:) origin:sender];
    }
    

    This is what it looks like on the device (simulator): enter image description here