Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jaydeep-godhani/swiftdatepicker
SwiftDatePicker is a custom reusable date picker component for iOS, featuring a sleek UI with rounded corners, delegate-based action handling, and easy integration into any project. It supports minimum date selection, formatted date outputs, and logical day identifiers like "today" or "yesterday."
https://github.com/jaydeep-godhani/swiftdatepicker
custom-date-picker date datepicker ios ios-development swift swift5 uidatepicker xcode
Last synced: 7 days ago
JSON representation
SwiftDatePicker is a custom reusable date picker component for iOS, featuring a sleek UI with rounded corners, delegate-based action handling, and easy integration into any project. It supports minimum date selection, formatted date outputs, and logical day identifiers like "today" or "yesterday."
- Host: GitHub
- URL: https://github.com/jaydeep-godhani/swiftdatepicker
- Owner: jaydeep-godhani
- License: mit
- Created: 2025-01-20T05:29:08.000Z (15 days ago)
- Default Branch: main
- Last Pushed: 2025-01-20T05:59:38.000Z (15 days ago)
- Last Synced: 2025-01-28T14:20:03.422Z (7 days ago)
- Topics: custom-date-picker, date, datepicker, ios, ios-development, swift, swift5, uidatepicker, xcode
- Language: Swift
- Homepage:
- Size: 315 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SwiftDatePicker
![GitHub repo size](https://img.shields.io/github/repo-size/jaydeep-godhani/SwiftDatePicker)
![GitHub stars](https://img.shields.io/github/stars/jaydeep-godhani/SwiftDatePicker?style=social)
![GitHub forks](https://img.shields.io/github/forks/jaydeep-godhani/SwiftDatePicker?style=social)**SwiftDatePicker** is a custom date picker implementation for iOS. It provides a visually appealing and reusable `DatePickerView` component that can be easily integrated into any iOS project. The date picker allows users to select a date, and its delegate methods enable handling actions like confirmation and cancellation.
## Features
- Customizable `UIDatePicker` with rounded background view.
- Delegate methods to handle `OK` and `Cancel` button actions.
- Dynamically adds and removes the date picker view.
- Supports minimum date selection starting from today.
- Provides formatted date strings and logical day identifiers (e.g., "today", "yesterday", "tomorrow").## Screenshots
## Installation
To integrate **SwiftDatePicker** into your project:
1. Clone the repository or download the source code.
2. Copy the `DatePickerView.xib` and `DatePickerView.swift` files into your project.
3. Link the `DatePickerView` class with the corresponding `.xib` file.## Usage
### 1. Adding the Date Picker
In your `UIViewController`:
```swift
@IBAction func datePickerButtonAction(_ sender: UIButton) {
self.view.endEditing(true)
self.addDatePickerView()
}func addDatePickerView() {
let datePickerView = DatePickerView(frame: self.view.bounds)
datePickerView.tag = 1001
datePickerView.delegate = self
datePickerView.datePicker.date = Date()
datePickerView.datePicker.minimumDate = Date()
self.view.addSubview(datePickerView)
self.view.bringSubviewToFront(datePickerView)
}
```### 2. Handling Delegate Methods
Conform to the `DatePickerViewDelegate` protocol to handle the button actions:
```swift
extension ViewController: DatePickerViewDelegate {
func datePickerOkButtonAction(view: DatePickerView, sender: UIButton, date: Date) {
// Handle selected date
print("Selected Date:", date)
self.removeSubView()
}
func datePickerCancelButtonAction(view: DatePickerView, sender: UIButton) {
// Handle cancellation
self.removeSubView()
}
}
```### 3. Removing the Date Picker View
```swift
func removeSubView() {
for subview in self.view.subviews {
if subview.tag == 1001 {
subview.removeFromSuperview()
}
}
}
```## Customization
You can easily modify the appearance of the `DatePickerView`:
- Change the background color of `datePickerBackgroundView` for a different look.
- Modify the corner radius for the `datePickerBackgroundView` in the `setDatePickerUI()` method.
- Add more UI elements to the `DatePickerView.xib` file if needed.## Requirements
- iOS 13.0+
- Swift 5
- Xcode 12 or higher## Contributing
Contributions are welcome! Please fork the repository and submit a pull request for any enhancements or bug fixes.
## License
This project is licensed under the MIT License. See the [`LICENSE`](LICENSE) file for details.
## Author
Developed by [Jaydeep Godhani](https://github.com/jaydeep-godhani). If you have any questions or feedback, feel free to reach out!
## Acknowledgments
- Thanks to the iOS community for their continuous support and inspiration!