GithubHelp home page GithubHelp logo

rheyansh / rpicker Goto Github PK

View Code? Open in Web Editor NEW
147.0 5.0 23.0 1.7 MB

Simple and Easy-to-Use iOS Swift Date and Options Picker

License: MIT License

Swift 100.00%
ios swift picker datepicker optionspicker pickerview options-picker

rpicker's Introduction

RPicker

Elegant and Easy-to-Use Swift Date and Options Picker. Master branch has the latest code and compatible with Swift 5. Check other branches for various Swift versions

What's New

  • iOS 14 Support with various UIDatePickerStyle e.g. Wheel, Inline, Compact
  • Dark Mode and Light Mode Support
  • Objective C Support [See How to use in Objective C Heading of this file]

Alt text Alt text Alt text Alt text

How to use

Add RPicker.swift into your project. You are ready to go!

// Simple Date Picker
    RPicker.selectDate {[weak self] (selectedDate) in
        // TODO: Your implementation for date
        self?.outputLabel.text = selectedDate.dateString("MMM-dd-YYYY")
    }
    
    // Simple Date Picker with title
    RPicker.selectDate(title: "Select Date", didSelectDate: {[weak self] (selectedDate) in
        // TODO: Your implementation for date
        self?.outputLabel.text = selectedDate.dateString("MMM-dd-YYYY")
    })
    
    // Simple Time Picker
    RPicker.selectDate(title: "Select Time", cancelText: "Cancel", datePickerMode: .time, didSelectDate: { [weak self](selectedDate) in
        // TODO: Your implementation for date
        self?.outputLabel.text = selectedDate.dateString("hh:mm a")
    })
    
    // Simple Date and Time Picker
    RPicker.selectDate(title: "Select Date & Time", cancelText: "Cancel", datePickerMode: .dateAndTime, minDate: Date(), maxDate: Date().dateByAddingYears(5), didSelectDate: {[weak self] (selectedDate) in
        // TODO: Your implementation for date
        self?.outputLabel.text = selectedDate.dateString()
    })
    
    //Show date picker with min and max date
    RPicker.selectDate(title: "Select Date", minDate: Date(), maxDate: Date().dateByAddingYears(5), didSelectDate: {[weak self] (selectedDate) in
        // TODO: Your implementation for date
        self?.outputLabel.text = selectedDate.dateString("MMM-dd-YYYY")
    })
    
    // Simple Option Picker
    let dummyList = ["Apple", "Orange", "Banana", "Mango", "Bilberry", "Blackberry"]

    RPicker.selectOption(dataArray: dummyList) {[weak self] (selctedText, atIndex) in
        // TODO: Your implementation for selection
        self?.outputLabel.text = selctedText + " selcted at \(atIndex)"
    }
    
    // Simple Option Picker with selected index
    let dummyList = ["Apple", "Orange", "Banana", "Mango"]
    RPicker.selectOption(title: "Select", cancelText: "Cancel", dataArray: dummyList, selectedIndex: 2) {[weak self] (selctedText, atIndex) in
        // TODO: Your implementation for selection
        self?.outputLabel.text = selctedText + " selcted at \(atIndex)"
    }
    
    //Date picker with pre selected date
    let selectedDate = Date().dateByAddingYears(-6)
    let maxDate = Date()
    let minDate = Date().dateByAddingYears(-12)
    
    RPicker.selectDate(title: "Select", selectedDate: selectedDate, minDate: minDate, maxDate: maxDate) { [weak self] (selectedDate) in
        // TODO: Your implementation for date
        self?.outputLabel.text = selectedDate.dateString("MMM-dd-YYYY")
        
    }
    
   //Show date picker iOS 14 -> Inline mode
        RPicker.selectDate(title: "Select Date", cancelText: "Cancel", datePickerMode: .date, style: .Inline, didSelectDate: {[weak self] (selectedDate) in
            // TODO: Your implementation for date
            self?.outputLabel.text = selectedDate.dateString("MMM-dd-YYYY")
        })
        
        //Show time picker iOS 14 -> Inline mode
        RPicker.selectDate(title: "Select Time", cancelText: "Cancel", datePickerMode: .time, style: .Inline, didSelectDate: {[weak self] (selectedDate) in
            // TODO: Your implementation for date
            self?.outputLabel.text = selectedDate.dateString("hh:mm a")
        })
        
        //Show date and time picker iOS 14 -> Inline mode
        RPicker.selectDate(title: "Select Date and Time", cancelText: "Cancel", datePickerMode: .dateAndTime, style: .Inline, didSelectDate: {[weak self] (selectedDate) in
            // TODO: Your implementation for date
            self?.outputLabel.text = selectedDate.dateString()
        })
        
        //Show date and time picker iOS 14 -> Compact mode
        RPicker.selectDate(title: "Select Date and Time", cancelText: "Cancel", datePickerMode: .dateAndTime, style: .Compact, didSelectDate: {[weak self] (selectedDate) in
            // TODO: Your implementation for date
            self?.outputLabel.text = selectedDate.dateString()
        })

How to use in Objective C

Date Picker

[RPicker selectDateWithTitle:@"Select" cancelText:@"Cancel" doneText:@"Done" datePickerMode:UIDatePickerModeDate selectedDate:dateValue minDate:nil maxDate:nil style: RDatePickerStyleWheel didSelectDate:^(NSDate * _Nonnull date) {
   
}];

Option Picker

     NSArray *list = @[@"Banana", @"Apple", @"Orange"];
     
     [RPicker pickOptionWithTitle:@"Select" cancelText:@"Cancel" doneText:@"Done" dataArray:list selectedIndex:[NSNumber numberWithInt:2] didSelectValue:^(NSString * _Nonnull value, NSInteger index) {
        
     }];

Author

Communication

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

License

RPicker is available under the MIT license. See the LICENSE file for more info.

Other Libraries

  • RBiometric:- Elegant and Easy-to-Use library for iOS Biometric (TouchId and FaceId) authentication.
  • RFirebaseMessaging:- Project provides basic idea and approach for building small social media application using firebase and implementing chat using Firebase.
  • RBeacon:- Sample project for turning android device into a Beacon device. App can work as both broadcaster and receiver.
  • RPdfGenerator:- A sample project to generate PDF file from data using itextpdf/itext7 library.

rpicker's People

Contributors

rheyansh 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

rpicker's Issues

iOS 14 broken

Screenshot 2020-10-18 at 10 40 07 AM

Hello developer. I hope you are doing well and passing a tight schedule. RPicker is broken for iOS 14. Any solution for this? I am eagerly waiting for your reply

Xcode11 Not working

Please update code for swift5 and New Xcode11.its working fine for ios12 but not working in ios13.it wont work for appdelegate currentViewController.

Localisation

Does this support localisation?
Specifically support for RTL?

Not working in iOS 12 and below

I have added RPicker.swift file in my project but show version issue. As connectedscenes is available in iOS 13 and above. Please suggest some universal code for that.

How to dismiss keyboard?

I'm using your RPicker for textfields which are inside of tableviewcell. How to dismiss textfield keyboard when pickerview appears. I'm doing textField.resignFirstResponder(). but not working. Please help me.

Background Color - Don't see the fonts If have Dark Template

Hi rheyansh!

Thanks for all for this PickerView that you build.
I have detected that, if you have the Dark Theme Set up in your iPhone, I can't see the fonts.

I have a solution if I change the background color.

datePicker.backgroundColor = UIColor.black

How can I know if the iPhone has the Dark Theme or the Light Theme?
Regards!
Bye :)

InlineDatePicker issue

when i opened inline datePicker in landscape mode "Done,Cancel and Select Date" UIDesign is missing..

Simulator Screen Shot - iPhone 12 mini - 2023-02-08 at 11 42 21
Simulator Screen Shot - iPhone 12 mini - 2023-02-08 at 11 59 06

Disable two Index of the DatePicker

Hi Rheyansh! Very useful your datePicker. Thank you very much for your time!
This is my problem...I need to disable the selection of two options in my array.
For example If I have:

// Simple Option Picker
let dummyList = ["Apple", "Orange", "Banana", "Mango"]
RPicker.selectOption(dataArray: dummyList) { (selctedText, atIndex) in
            // TODO: Your implementation for selection
        }

How can I disable the selection of the index 1 or 3 (Orange or Mango) ?
Thanks for all!
Regards

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.