GithubHelp home page GithubHelp logo

meorge / timezonepicker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gligorkot/timezonepicker

0.0 2.0 1.0 560 KB

A TimeZonePicker UIViewController similar to the iOS Settings app. Search and select from a range of cities and countries to find your most suitable time zone.

License: Apache License 2.0

Swift 89.83% Ruby 10.17%

timezonepicker's Introduction

TimeZonePicker

Build Status codebeat badge Version License Platform

Buy Me a Coffee at ko-fi.com

A TimeZonePicker UIViewController and SwiftUI View similar to the iOS Settings app. Search and select from a range of cities and countries to find your most suitable time zone.

Screenshots

Installation

CocoaPods

To install it in your iOS project, install with CocoaPods

pod 'TimeZonePicker'

Usage

Basic Initialisation

To initialise a timeZonePicker you can use the class function getVC(withDelegate: TimeZonePickerDelegate) on the TimeZonePickerViewController as below:

let timeZonePicker = TimeZonePickerViewController.getVC(withDelegate: self)

Then you can use the timeZonePicker as you would any UIViewController, for example:

present(timeZonePicker, animated: true, completion: nil)

TimeZonePickerDelegate

The TimeZonePickerDelegate currently has only one method that needs to be implemented:

func timeZonePicker(_ timeZonePicker: TimeZonePickerViewController, didSelectTimeZone timeZone: TimeZone)

Once an item is selected from the table of cities/countries the above delegate method gets called, conveniently returning the TimeZonePickerViewController and the selected TimeZone. You can use the timeZonePicker to dismiss it here and the timeZone as you need it in your application. For example:

func timeZonePicker(_ timeZonePicker: TimeZonePickerViewController, didSelectTimeZone timeZone: TimeZone) {
    timeZoneName.text = timeZone.identifier
    timeZoneOffset.text = timeZone.abbreviation()
    timeZonePicker.dismiss(animated: true, completion: nil)
}

Please check the TimeZonePickerExample project for the above usage example. If you have any questions do not hesitate to get in touch with me.

SwiftUI

In addition to the UIKit-based view controllers, there is also a SwiftUI View available, called TimeZonePreviewSelectionView.

Preview view Select view

To use TimeZonePicker in a SwiftUI app, include TimeZonePreviewSelectionView() in your View, and bind it to a CityCountryTimeZone variable, like so:

struct ContentView: View {
    // variable storing the time zone data
    @State var myTimeZone: CityCountryTimeZone = CityCountryTimeZone()
    
    var body: some View {
        VStack {
            // Creates the time zone preview picker
            TimeZonePreviewSelectionView(cityItem: self.$myTimeZone)
            
            // Displays the selected time zone
            Text("The selected time zone is \(self.myTimeZone.timeZoneName)")
        }
    }
}

Note: So far, this has only been tested on macOS Catalina. It should work on iOS as well, but it is not guaranteed yet.

Requirements

  • iOS 8 or later.
  • Swift 3

License

Copyright (c) 2017 Gligor Kotushevski

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

timezonepicker's People

Contributors

gligorkot avatar meorge avatar gonencmete avatar

Watchers

James Cloos avatar  avatar

Forkers

jalurgemilang

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.