Git Product home page Git Product logo

addatepicker's Introduction

ADDatePicker: Horizontal Date Picker

ADDatePicker is Horizontal Date Picker Library written in Swift

Requirements

  • iOS 10.0+
  • Xcode 10.0+
  • Swift 4.2+

Communication

  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

CocoaPods 1.1+ is required

To integrate ADDatePicker into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

target '<Your Target Name>' do
pod 'ADDatePicker'
end

Then, run the following command:

$ pod install

Usage

  • First, set Custom Class of UIView to ADDatePicker...

..And That's it., you can run the project now. it's that simple. ;]

Demo

Customize with ease..!

Customization

"Listen up, Dave. Your code is poor and colour choices are even poorer. this doesn't look good"

"Calm Down Joe, I gotchu.."

 @IBOutlet weak var datePicker: ADDatePicker!

1. Reset Range of years.

 datePicker.yearRange(inBetween: 1990, end: 2022)

2. Set Intial Date to Picker.

 datePicker.intialDate = Date()

3. Yay, Colours.. or Colors. (depends.. where you came from)

  //set BackGround Color of DatePicker
  datePicker.bgColor = .blue

  //set Selection and Deselection Background Colors
      
  datePicker.deselectedBgColor = .clear
  datePicker.selectedBgColor = .white
      
  //set Selection and Deselection Text Colors
  datePicker.selectedTextColor = .black 
  datePicker.deselectTextColor = UIColor.init(white: 1.0, alpha: 0.7)

4. Customize Selector..

Currently, there are three selectionType available. you're most welcome to contribute if you want to extand this list.

 enum SelectionType {
     case square
     case roundedsquare
     case circle
 }    

You can change selector by writing this piece of code.

 datePicker.selectionType = .circle

5. Delegate Methods..

Now, You can confirm to Delegate method to access date on scroll

datePicker.delegate = self
func ADDatePicker(didChange date: Date)

Which allows you to get new date on every scroll.

Credits

ADDatePicker is developed under observation of the great minds of Space-O Technology

License

ADDatePicker is released under the MIT license. See License for details.

addatepicker's People

Contributors

abhi-dave avatar pratik-sodha avatar sameer4 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

addatepicker's Issues

App crash on 31 March

From debugging..it seems days model does't contain 31
so

let d = days.index { (modelObj) -> Bool in return Int(modelObj.type) == Int(dd) }

gives nil and crashes on days[d!].isSelected = true

Returning incorrect date (previous day in my case) for timezones other than GMT

The issue happens in devices in timezones other that GMT. The returned day is the previous day of the day picked by the user. That happens because when converting the date string to Date the timezone is not taken into account (DateFormatter assumes 00:00 for GMT). And if your timezone is not GMT when using or visualising the Date it is converted to YOUR timezone and if it is for example GMT-1, you date has been changed to the previous day at 23:00.

How to fix? The following change fixed the issue for me.
In CalendarHelper.swift change:

let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MM/dd/yyyy"
if currentDay == "" {
       currentDay = (days.last?.type)!
}
let date = dateFormatter.date(from: "\(currentMonth)/\(currentDay)/\(currentYear)")

to

let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MM/dd/yyyy"
if currentDay == "" {
       currentDay = (days.last?.type)!
}
dateFormatter.locale = Locale.current // Added line
dateFormatter.timeZone = TimeZone(secondsFromGMT: 0) // Added line
let date = dateFormatter.date(from: "\(currentMonth)/\(currentDay)/\(currentYear)")

Feature Request: Limit scrolling of days by range of days before and after current date

I'd like to be able to limit the number of days we can scroll.

For example +/- 3 days from today (August 25th)

func limitScrollingOfDays(daysBefore before: Int, daysAfter after: Int, from selectedDate) {
    //TODO: Logic here
}

And be used like:

datePicker.limitScrollingOfDays(daysBefore: 3, daysAfter: 10, from: Date())

It should limit the number of scrolling days from August 22nd to September 4th

Strange issue with miss-aligned labels.

It seems the labels are miss-aligned. I've used Arial 16points font.
Maybe some calculation issues with a reminder? We did not check the code :)

Screenshot 2020-02-28 at 4 11 48 PM

Would be nice to find a fix for this bug ๐Ÿ‘

Error if iOS device preferred device language other than English

Error if iOS device preferred device language other than English.

Easy t test, just switch language from device Settings > General > Language & Region > Make any other language first on Preferred Language order.

Date picker will report error "Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value!" in CalendarHelper.swift "return date!" line 89

Happy NewYear

class func getYears(startYear: Int = 1980, endYear: Int = 2018) ;

I recommend changing the default value of endYear of the method func getYears(startYear:Int = 1980,endYear:Int = 2018) to the current year, otherwise it will crash if there is no age range set.

Need just month and year picker

I Need a just month and year picker...i was thinking to give some -ve top dates section get hidden :D but not working...so can i have it as feature like a fixed height from user and then he can control what to show or option to make picker just for month and year

Feature request: Choose which elements to display and add weekdays as a new element

I'd like to be able to display weekdays inside the scrolls and decide if I want to display for example year or maybe number of days

Something like:

MON | TUE | WED | THUR | FRI | SAT | SUN
   1     |    2   |    3    |     4        5   |    6   |    7
JAN   | ....

And a method like:

func displayElements(_ elements: [ElementType]) {
    //Logic here
}

That would be called like:

datePicker.displayElements([.weekday, .day, .month])

The code above would display weekdays, days and months

While this one below would display only months and years:

datePicker.displayElements([.month, .year])

Leap year date issue

i have found an issue on leap year. after launching it current date. i am trying to move the year section (2016) and then month section (feb). after that i have found that 29th is selected but not moved to the selected area of the picker. this happen when our first launching current date is like 31-03-20
screen shot 2018-08-28 at 4 30 24 pm
screen shot 2018-08-28 at 4 32 07 pm

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.