thcalendardatepicker

Description

THCalendarDatePicker is a lightweight, fully customizable date picker library for iOS. It provides an elegant and user-friendly interface for selecting dates in iOS applications.

Features

  • Simple and intuitive date selection.
  • Supports both portrait and landscape orientations.
  • Customizable appearance and behavior.
  • Ability to select a specific date range.
  • Option to limit the selection to weekdays only.
  • Delegate methods for handling user interactions.

Installation

To install THCalendarDatePicker, you can use either CocoaPods or manually add the library to your project.

CocoaPods

  • Add THCalendarDatePicker to your Podfile:
pod 'THCalendarDatePicker'
  • Run the command pod install.
  • Import the library in your code:
@import THCalendarDatePicker;

Manual Installation

  • Download the latest version of THCalendarDatePicker from the GitHub repository.
  • Drag and drop the THCalendarDatePicker folder into your Xcode project.
  • Import the library in your code:
#import "THDatePickerViewController.h"

Basic Usage

To use THCalendarDatePicker, follow these steps:

  1. Instantiate a THDatePickerViewController:
THDatePickerViewController *datePicker = [[THDatePickerViewController alloc] initWithDate:[NSDate date]];
datePicker.delegate = self;

// Customize the date picker appearance and behavior
// datePicker.date = [NSDate dateWithTimeIntervalSinceNow:60*60*24*3];
// datePicker.disableWeekends = YES;
// ...

// Present the date picker view controller
[self presentViewController:datePicker animated:YES completion:nil];
  1. Implement the THDatePickerDelegate methods to handle user interactions:
- (void)datePickerDonePressed:(THDatePickerViewController *)datePicker {
    NSLog(@"%@", datePicker.date);
    // Handle the selected date
}

- (void)datePickerCancelPressed:(THDatePickerViewController *)datePicker {
    // Handle cancel button pressed
}

- (void)datePicker:(THDatePickerViewController *)datePicker selectedDate:(NSDate *)selectedDate {
    NSLog(@"%@", selectedDate);
    // Handle date selection
}

Customization

THCalendarDatePicker provides various properties to customize the appearance and behavior:

  • date: The selected date.
  • disableWeekends: A boolean value to limit the selection to weekdays only.
  • autoCloseOnSelectDate: A boolean value to automatically dismiss the date picker upon selecting a date.
  • setDateFont: and setOldDateFont:: Methods to set custom fonts for the selected and old dates.
  • setLocale:: Method to set a specific locale for the date picker.
  • setTheme:: Method to set a custom theme for the date picker.
  • setDateFormat:: Method to set a custom date format for the displayed dates.
  • And more…

Examples

Here are some common use cases for THCalendarDatePicker:

Example 1: Basic Date Selection

Allow the user to select any date from today onwards.

THDatePickerViewController *datePicker = [[THDatePickerViewController alloc] initWithDate:[NSDate date]];
datePicker.delegate = self;
[self presentViewController:datePicker animated:YES completion:nil];

Example 2: Date Range Selection

Limit the date selection to a specific date range.

THDatePickerViewController *datePicker = [[THDatePickerViewController alloc] initWithDate:[NSDate date]];
datePicker.delegate = self;
datePicker.date = [NSDate dateWithTimeIntervalSinceNow:60*60*24*3]; // Set a date 3 days from now
[self presentViewController:datePicker animated:YES completion:nil];

Example 3: Custom Appearance

Customize the appearance of the date picker.

// Set custom fonts for the selected and old dates
[datePicker setDateFont:[UIFont systemFontOfSize:16]];
[datePicker setOldDateFont:[UIFont fontWithName:@"Helvetica-Bold" size:16]];

// Set the preferred date format
[datePicker setDateFormat:@"dd/MM/yyyy"];

// Set a custom theme
THDatePickerTheme *theme = [[THDatePickerTheme alloc] initWithPrimaryColor:[UIColor redColor] secondaryColor:[UIColor whiteColor] fontColor:[UIColor blackColor] fontHighlightColor:[UIColor whiteColor]];
[datePicker setTheme:theme];

// Present the date picker view controller
[self presentViewController:datePicker animated:YES completion:nil];

Notes

  • The delegate methods are optional and can be used to handle specific events.
  • The date picker automatically dismisses if autoCloseOnSelectDate is set to YES.
  • Make sure to respect the library’s license terms as defined in the GitHub repository.
  • Remember to link the necessary frameworks and libraries as mentioned in the repository.

Conclusion

THCalendarDatePicker is a versatile and user-friendly date picker library for iOS applications. With easy integration and extensive customization options, it provides an excellent solution for date selection needs. Feel free to explore the library’s documentation and experiment with various configurations to enhance your app’s user experience.