Giter Club home page Giter Club logo

acid.dialogpicker's Introduction

Acid.DialogPicker

Acid.DialogPicker is a C# iOS component that display a UIPickerView and UIDatePicker inside a Modal Window for Xamarin. Date Picker Regular Picker

Requirements

  • Xamarin.iOS
  • Visual Studio for Mac
  • Visual Studio 2017(windows)
  • Windows: Mac paired to Windows machine to test.

Installation

NuGet

You can use NuGet to install Acid.DialogPicker, only run this command:

Install-Package Acid.DialogPicker

Visual Studio:

  • Right-click on your iOS Project
  • Select Add NuGet Packages
  • Search "Acid.DialogPicker"

Downloading the Source:

Include in your project:

  • Acid.BaseDialogPicker.cs
  • Acid.DatePicker.Dialog.cs
  • Acid.Picker.Dialog.cs

Use the Library

With this package you get this 3 files:

  • Acid.BaseDialogPicker.cs: Abstract class, it can hold another type of View inside a Modal Window.
  • Acid.DatePicker.Dialog.cs: Inherit from BaseDialogPicker, it display a UIDatePickerView
  • Acid.Picker.Dialog: Inherit from BaseDialogPicker and display a UIPickerView also it exposes some API for UIPickerDataSource and UIPickerDelegate.

After you install the NuGet Package or drop the files inside your project, go to your View that you want to display our dialog and use the Namespace In your view add this:

using AcidStudios.iOS.Dialog

To show the DatePicker.Dialog use this code: In your view add this:

var datePicker = new AcidStudios.iOS.Dialog.DatePickerDialog(new Foundation.NSLocale("es_US"), true);
datePicker.Show("Hello there", "OK", "Cancel", Foundation.NSDate.Now, Foundation.NSDate.Now.AddSeconds(-40000), Foundation.NSDate.Now, UIDatePickerMode.Date,(Foundation.NSDate obj) => {
	if (obj != null)
	{
		Console.WriteLine(obj.ToString());
	}
});

To show the Picker.Dialog use this code: In your view add this:

// Create yout collection of Options for your Picker
var items = new System.Collections.Generic.List<Country>
{
	new Country { Name = "México" },
	new Country { Name = "United States" },
	new Country { Name = "Canada" }
};

// Create Picker.Dialog
// Implement some UIPickerDelegate and UIPickerDataSource delegate functions
var picker = new AcidStudios.iOS.Dialog.PickerDialog<Country>(true)
{
	ComponentCount = delegate (UIPickerView pickerView)
	{
		return 1;
	},
	RowsInComponent = delegate (UIPickerView pickerView, nint component)
	{
		return items.Count;
	},
	TitleForRow = delegate (UIPickerView pickerView, nint row, nint component)
	{
		return new Foundation.NSString(items[(int)row].Name);
	}
};

// Use Show to Display the Picker Dialog and define the callback 
// function to retrieve the index of selected row.
picker.Show("Regular Picker", "OK", "Cancel", (nint obj) =>
{
	if (obj != -1 && items[(int)obj] is Country country)
	{
		Console.WriteLine($"Selected Country: {country.Name}");
	}
});

Special thanks to

License

This code is distributed under the terms and conditions of the MIT license.

acid.dialogpicker's People

Contributors

tavobarrientos avatar

Watchers

 avatar James Cloos avatar  avatar

acid.dialogpicker's Issues

iOS 14 Date Picker Issue

iOS 14 no longer supports this date picker initialisation format. This can be solved by adding a UIDatePickerStyle and SizeToFit. See this thread.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.