1

Since UIPickerView can't be customized to the level I want (without taking a risk by hiding specific subviews), I need to roll my own to select a time.

I figure I can do this using two UITableViews, but I'm unsure of how to do 2 things:

1) How do I determine which cell is in the middle of the view (i.e. which one did the user select)?

2) How do I make the table snap to the cell nearest to the middle of the view once the user has stopped scrolling?

Thanks for your help.

bmueller
  • 2,681
  • 1
  • 27
  • 45

4 Answers4

2

Why do you say that UIPickerView can't be customized?. It has a bunch of delegate methods made to allow a lot of customization, such as view for rows, height for rows etc etc..

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIPickerViewDelegate_Protocol/Reference/UIPickerViewDelegate.html

Implement the delegate in your ViewController and customize it as you want.

Pauls
  • 2,596
  • 19
  • 19
  • My mistake - I know that UIDatePicker can't be customized, so I thought it was the same for UIPickerView. Can you get rid of the Picker View's frame, though? I'm going for a minimalist look in my app. – bmueller Mar 18 '13 at 18:39
  • I have never done that before, I don't think there is an easy way to remove the frame since there is no delegate method for that. You will probably need to subclass from UIPickerView and override the layoutSubviews method checking the layers that are there by default and remove them. But not sure if this can work fine at the end. – Pauls Mar 18 '13 at 18:47
0

You're just trying to select a time? Then use UIDatePicker. It is a picker view for time/date.

Mike Z
  • 4,121
  • 2
  • 31
  • 53
0

Depending on the type of customisation that you want, you might not need to make your own UIPickerView. You can return your own views for each component using UIPickerViewDelegate. Check pickerView:viewForRow:forComponent:reusingView:

palpoms
  • 96
  • 4
0

The free Sensible TableView framework has a UITableView based date picker that you could use out of the box. Should save you a lot of time as it handles all the scrolling and table view resizing. Hope this helps.

Matt
  • 2,391
  • 2
  • 17
  • 18