Overview
ESDatePicker is a lightweight and fully customizable date picker library for iOS apps. It provides an easy-to-use interface for selecting dates with various styling options.
Features
- Flexible and customizable date picker
- Supports various date formats
- Multiple selection modes (single day, range, multi-selection)
- Customizable styling options
- Delegate methods for handling date selection events
- Localization support
- Supports both portrait and landscape orientations
- Compatible with iOS 9.0+
Installation
To install ESDatePicker in your iOS project, you have two options: using CocoaPods or manually integrating the library.
Using CocoaPods:
pod 'ESDatePicker'
Manually:
1. Download the latest version of ESDatePicker from the GitHub repository.
2. Drag and drop the “ESDatePickerController.swift” and “ESDatePickerView.swift” files into your Xcode project.
3. Ensure that the necessary dependencies (such as UIKit) are included in your project.
Usage
To use ESDatePicker in your iOS app, follow these steps:
1. Import the ESDatePicker module:
import ESDatePicker
2. Create an instance of ESDatePickerController:
let datePickerVC = ESDatePickerController()
3. Set the desired date picker properties (e.g., date format, selection mode, etc.):
datePickerVC.dateFormat = "dd/MM/yyyy"
datePickerVC.selectionMode = .range
4. Present the date picker view controller:
present(datePickerVC, animated: true, completion: nil)
Delegate Methods
ESDatePicker provides several delegate methods to handle date selection events. You can conform to the ESDatePickerDelegate
protocol and implement these methods in your view controller:
func datePicker(selected dates: [Date])
Called when the user selects dates. Returns an array of selected dates.
func datePicker(didChangeMonth month: Int, year: Int)
Called when the currently displayed month or year changes. Returns the new month and year values.
Customization
ESDatePicker offers various customization options to tailor the appearance and behavior of the date picker.
Some of the available properties include:
backgroundColor
: The background color of the date picker view.textColor
: The color for the date labels.highlightedTextColor
: The color for highlighted (selected) dates.selectionMode
: The selection mode for the date picker (single day, range, multi-selection).dateFormat
: The format for displaying selected dates.minimumDate
: The minimum selectable date.maximumDate
: The maximum selectable date.disabledDates
: An array of dates to disable (grayed out and not selectable).
You can customize the date picker by modifying these properties before presenting it to the user.
Localization
ESDatePicker supports localization, allowing you to display the date picker in different languages.
To localize the date picker, follow these steps:
1. Create a Localizable.strings
file for each desired language.
2. Add the translations for the necessary keys:
"MonthNames" = "January,February,March,April,May,June,July,August,September,October,November,December";
"ShortMonthNames" = "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec";
"WeekdayNames" = "Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday";
"ShortWeekdayNames" = "Sun,Mon,Tue,Wed,Thu,Fri,Sat";
3. Set the localized strings for the date picker:
let locale = Locale(identifier: "en") // Example for English
datePickerVC.locale = locale
Replace “en” with the appropriate identifier for the desired language.
Compatibility
ESDatePicker is compatible with iOS 9.0 and later.
License
ESDatePicker is released under the MIT License.