Search code examples
iosswiftios8uidatepicker

Custom picker which can able to select two times at a time


How to design this screen in iOS.

enter image description here

It can select two times at a time, is it possible if so what is the approach?


Solution

  • Thank you @Sudhin Davis that was a nice idea, but finally i decided to continue without any change in UI. I found the solution from @Harry's comment. Here is what i did to fix it

    let maxV = 25000
    override func awakeFromNib() {
        self.pickerVIew.delegate = self
        self.pickerVIew.dataSource = self
        self.pickerViewLoaded(0, component: 0)
        self.pickerViewLoaded(0, component: 1)
        self.pickerViewLoaded(0, component: 3)
        self.pickerViewLoaded(0, component: 4)
    
    }
    func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int
    {
        return 6
    }
    func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int
    {
        if(component == 2 || component == 5)
        {
            return 2
        }
        else
        {
            return maxV
        }
    }
    func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String!
    {
        if(component == 0 || component == 3)
        {
            return String(format: "%02d", (row%12)+1)
        }
        else if(component == 1 || component == 4)
        {
    
            return String(format: "%02d", (row%12)*5)
        }
        else
        {
            return row == 0 ? "AM" : "PM"
        }
    }
    func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
        self.pickerViewLoaded(row,component: component)
    }
    func pickerViewLoaded(row:Int,component:Int)
    {
        var base12 = (maxV/2)-(maxV/2)%12;
        self.pickerVIew.selectRow(row%12+base12, inComponent: component, animated: false)
    }