• Stars
    star
    202
  • Rank 189,790 (Top 4 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created over 9 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A lightweight DropDownList / ComboBox for iOS, written in Objective-C

DownPicker

DownPicker is an extremely light-weight class library for creating DropDownList / ComboBox controls for iOS that will behave like their HTML / Android counterparts. You'll only need a standard UITextField and few lines of code.

What does it do

It takes any UITextField already present in your code (including those added to a Storyboard):

alt text

and turns it into this:

alt text

It's as simple as that. You only need to provide an array of data.

NOTE: If you don't like the control wrapper approach, you can also use it as a custom control via the included UIDownPicker class: read the following paragraph for more info.

How does it work

DownPicker is basically a control interface wrapper, meaning that you won't use it as a control - it will use an existing UITextField control instead. This is a good thing, because you'll be able to design, positioning and skin your UITextField like you always do, programmatically or inside a Storyboard UI, depending on how you are used to work. You won't change your style, as it will adapt to suit yours.

However, if you don't like the control wrapper pattern, you can just use it as a custom control using the included UIDownPicker class. It's entirely up to you (and very easy to install in both scenarios).

Installation

Using CocoaPods

DownPicker is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "DownPicker"

CI Status Version License Platform

Manual Installation

Download the latest version from this link, then unzip & drag-drop the /DownPicker/ folder inside your iOS project. You can do that directly within Xcode, just be sure you have the copy items if needed and the create groups options checked.

How to Use

Once you have DownPicker installed and included in your project, you can either use it as a Control Wrapper or as a Custom Control: the choice is up to you, depending on your programming style.

As a Control Wrapper

Add (or choose) a UITextField you would like to transform to a DownPicker. You can use the Storyboard designer tool or do it programmatically; you can also set up constraints, custom placement/coords, font, colors and anything else you like. When you're done, open your controller's .h file and create a property for the DownPicker wrapper:

#import "DownPicker.h";

@property (strong, nonatomic) DownPicker *downPicker;

Then switch to the .m file and add these lines to your controller's viewDidAppear method:

// create the array of data
NSMutableArray* bandArray = [[NSMutableArray alloc] init];

// add some sample data
[bandArray addObject:@"Offsprings"];
[bandArray addObject:@"Radiohead"];
[bandArray addObject:@"Muse"];
[bandArray addObject:@"R.E.M."];
[bandArray addObject:@"The Killers"];
[bandArray addObject:@"Social Distortion"];

// bind yourTextField to DownPicker
self.downPicker = [[DownPicker alloc] initWithTextField:self.yourTextField withData:bandArray];

That's it. You can retrieve the user's choice at any time using self.datePicker.text or textField.text.

As a Custom Control

If you'd like to use DownPicker as a custom control instead, just instantiate the included UIDownPicker class programmatically and attach it to your view like any other legacy UI control:

@interface YourViewController () {
    UIDownPicker *_dp;
}
@end

@end
- (void)viewDidLoad
{
    [super viewDidLoad];
    self._dp = [[UIDownPicker] initWithData:yourMutableArray];
    [self.view addSubview:self._dp]; 
}

You can then customize it using the inner DownPicker public property.

Status Change event handling

You can bind your own delegate function to DownPicker's status change by using the UIControlEventValueChanged Control action in the following way:

[self.yourDownPicker addTarget:self 
    action:@selector(dp_Selected:)
    forControlEvents:UIControlEventValueChanged];

and then:

-(void)dp_Selected:(id)dp {
    NSString* selectedValue = [self.youtDownPicker text];
    // do what you want
}

Additional Features

You can also:

  • defer data loading using the [self.downPicker setData:array] method.
  • disable the right arrow image using the [self.downPicker showArrowImage:bool] method.
  • use a custom right arrow image using the [self.downPicker setArrowImage:UIImage*] method. You can use [UIImage imageNamed:@"yourCustomImage.png"] to set any image in your project.
  • configure (and/or localize) the placeholder text string using the [self.downPicker setPlaceholder:NSString*] and [self.downPicker setPlaceholderWhileSelecting:NSString] methods.
  • retrieve, customize and hook on the inner UIPickerView control using the [self.downPicker getPickerView] method (use at your own risk).
  • retrieve, customize and hook on the inner UITextField control using the [self.downPicker getTextField] method (use at your own risk). Remember that it's the exact same control you passed, so you might prefer to use your main reference instead.
  • the cancel button can be removed if the boolean flag property shouldDisplayCancelButton is set to NO after DownPicker is instantiated

Upcoming Features

  • More customization options (give me your suggestions).
  • Dynamic data-binding. ... and more!

Useful Links

Support

You can support this project's development by clicking on the following button.

Donate

Thanks a lot!

Author

Ryan, [email protected]

License

DownPicker is available under the MIT license. See the LICENSE file for more info.

More Repositories

1

CORSflare

A lightweight JavaScript CORS Reverse Proxy designed to run in a Cloudflare Worker.
JavaScript
143
star
2

bootstrap4-glyphicons

How use Glyphicons with Bootstrap 4 (without getting mad)
40
star
3

LockProvider

A lightweight C# class that can be used to selectively lock objects, resources or statement blocks according to given unique IDs.
C#
37
star
4

PasswordGenerator

A simple C# helper class for ASP.NET Core to generate a random password with custom strength requirements: min length, uppercase, lowercase, digits & more
C#
37
star
5

ASP.NET-Core-Web-API

Code repository for the Building Web APIs with ASP.NET Core Manning book by Valerio De Sanctis
C#
36
star
6

Tabulazer

A Chrome Extension to filter, sort, page and style any existing HTML table using the Tabulator JS library.
JavaScript
24
star
7

REPflare

A lightweight Cloudflare Worker to replace text and inject styles and scripts in any web page
JavaScript
22
star
8

RunningLow

Free PowerShell script to to check for low disk space on local and network drives and send e-mail alerts when it goes under a user-defined quota.
PowerShell
19
star
9

WindowsService.NET

A sample Windows Service (.NET Framework) C# boilerplate.
C#
18
star
10

FFmpeg-scripts

A collection of FFmpeg related bash scripts to perform video and/or audio real-time streaming over online streaming services such as Periscope and YouTube.
Shell
16
star
11

Disable-Inactive-ADAccounts

A small Powershell script that disables all the Active Directory user accounts inactive for more than X days.
PowerShell
12
star
12

dir2json

A PHP CLI script to ouput the contents of a whole directory tree to a JSON object
PHP
11
star
13

AESCrypt

Yet Another AES-Rijndael ASP.NET C# implementation with advanced configuration settings
C#
11
star
14

dobble

A JavaScript function to generate combinatorial geometric series for games such as Dobble (aka Spot it!) and to better understand the math logic behind them.
JavaScript
10
star
15

MergeTIFF

A lightweight .NET Core console program to merge multiple TIFF files into one.
C#
9
star
16

react-native-firebase-notifications

React Native sample app for Android and iOS with Push Notifications support using Firebase SDK and API.
Java
9
star
17

publicize-with-hashtags

Wordpress Plugin that automatically appends hashtags to content sent by Jetpack Publicize module. Hashtags will be created using post tags. Also includes dupe check, max char length check, space trimming & more.
PHP
8
star
18

CustomContent

A MantisBT 2.x plugin to insert custom HTML, PHP, JS and/or CSS in the Mantis Bug Tracker HTML layout.
PHP
7
star
19

jquery.scrolling

adds the *scrollin* and *scrollout* events to jquery, which will fire when any given element becomes (respectively) visible and invisible in the browser viewpori
JavaScript
6
star
20

SourceControlSwitcher

A lightweight Visual Studio Extension that automatically sets the Source Control Provider according to the one used by the current Visual Studio project.
C#
6
star
21

RegExSplitter

Split a single-line JavaScript Regular Expression into multiple lines of code.
JavaScript
4
star
22

EmailValidator

A lightweight and customizable helper class to validate any e-mail address using the HTML living standards RegEx and/or ASP.NET Core built-in validators in C#
C#
3
star
23

NETCore-AzureSQL

A sample .NET Core App to show how to securely connect to an Azure SQL Database using managed identity.
C#
2
star
24

ASP.NET-Core-8-and-Angular

Official repository for ASP.NET Core 8 and Angular book by Valerio De Sanctis
C#
1
star
25

NETConf2020-ASP-NET-5-Structured-Logging

ASP.NET 5 Structured Application Logging samples using Application Insights (MS Azure) and Serilog (SQL Server, MariaDB)
TypeScript
1
star