How to create DropDown in xcode?
Solution 1
Here I found two demos for dropDown list, One is creating custom expandable UITableViewCell
like :-
to
source code :- DEMO
AND Another is custom Drop Down list like:-
by clicking of test then open drop down list as bellow like image
source code with Tab Bar:-DEMO
updated source code without Tab Bar :-
http://www.sendspace.com/file/83qws5
Solution 2
I beleive you shouldn't use dropdown boxes in iOS, as it's a desktop OS UI control element. You should think up something else using existing components (like PickerView), that's the words for UI consistency.
And if you need this anyway, you may create a table view, place it beneath your label and a triangular button(which causes it to appear and disappear) and populate it with values.
Solution 3
Since there are no native DropDown
elements in iOS, you could make use of a TextField
with custom background and a UITableView
to accomplish that. Here is how to go about it.
Pseudocode
- Create a
TextField
and set it's delegate to parent controller - Implement
UITextFieldDelegate
and implement thetextFieldShouldBeginEditing
method - Create a new
UIViewController
and implementUITableView
in it programmatically. - Create a custom protocol and create it's object (delegate) it.
- In
textFieldShouldBeginEditing
method, load this controller and present it modally passing the required table's data source and set delegate as parent. - in the new
tableViewController
, implementUITableViewDelegate
and implement the didSelectRowAtIndex path method. - Upon row selection, call the delegate with passing appropriate data.
- dismiss the modally presented controller.
Solution 4
just for whom searching for small simple swift combo box here in 2016 year, i've tried a few of old and new (but obj-c) libs, and at last selected this:
https://github.com/sw0906/SWCombox
Solution 5
The easy and simple way to design a drop down list is by representing it like a UITableView
and some animation. This makes it look really like a dropdownlist. Here is a code I used for creating one . For this first import the < QuartzCore/QuartzCore.h > framework.
-(IBAction)DropDownTable:(id)sender
{
TableView.hidden = NO;
if(TableView.frame.origin.y ==203)
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5f];
[TableView setFrame:CGRectMake(224, 204, 27, 160)];
[UIView commitAnimations];
[self.view TableView];
}
else if (TableView.frame.origin.y == 204)
{
[TableView setFrame:CGRectMake(224, 203, 27, 0)];
TableView.hidden = YES;
}
[self.view addSubview:TableActivityLevel];
}
First make a tableview , declare its methods and make the array . Put this function on the click of a UIButton
and youll see it work !!! Happy coding :)
Adnan Khan
Updated on July 31, 2022Comments
-
Adnan Khan almost 2 years
I am a very new developer for IOS, i need help, How to create dropdown box in xcode, any one provide me example to create country list in drop down?
-
Satish Azad over 10 yearsalso refer to github.com/satishazad/SAMenuDropDown
-
yazh over 9 years@Ramz please don't post broken link
-
-
Adnan Khan over 11 yearssecond dropdown is fine but i want this example with tab. could you give me any example?
-
Nitin Gohel over 11 yearsyou simply add tab bar controller in your project and impliment above projects method
-
Adnan Khan over 11 yearssorry nitin gohel, i want this example without tab, this example has already tabs.
-
Nitin Gohel over 11 yearswait i just epdate my answer without tab this example
-
Adnan Khan over 11 yearsi am a very new ipone developer, nitin Gohel could you help me to update dropdown on single view application, i dont want other files.
-
Nitin Gohel over 11 yearsmeans i can not understand what you doing in your app can you explain more?
-
Adnan Khan over 11 yearsbasically i have auto completed country box, i need to pull cities from the selected country, i have done auto completed country textbox, now i need simple dropdown in single view application, its quite difficult for me to move your current DropDown to move single view controller, could you help me?
-
Adnan Khan over 11 yearsi need your dropdown in single view application, no need other files and extra code.
-
Adnan Khan over 11 yearsIs this posible to create dropdown in single view application?
-
Adnan Khan over 11 yearsThanks, but i am still stuck my Main file #import <UIKit/UIKit.h> #import "AppDelegate.h" int main(int argc, char *argv[]) { @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); } } could you tell me what should i do, i replace code of your main file but its give me an errors.
-
Marcus Becker over 7 yearsIf you want to build it by your self: appcoda.com/expandable-table-view
-
ToolmakerSteve about 7 yearsBTW, the reliance on origin.y's value as a flag indicating whether dropdown is expanded seems very obscure [bad code smell]. I haven't looked closely at code, but hopefully it would not be hard to re-write it to use an explicit boolean flag to remember which state the dropdown is in.