How can we achieve such type of selected values to be changed with mins 开发者_如何学运维and secs in UIPickerView???
First, you use the pickerView:viewForRow:inComponent:reusingView:
data source method to return the "00" label. This is actually a bit tricky, since pickerview will alter the frame of this view to fill the row. That means you have to embed your properly positioned view inside another view, and then return that container view instead.
As for the labels, those are simply UILabel
objects that have been positioned correctly and added as subviews of the pickerview itself.
And to get them to update correctly, just change their titles in the pickerView:didSelectRow:inComponent:
method.
This is exactly what UIDatePicker
is doing.
You should implement UIPickerViewDelegate Protocol
and UIPickerViewDataSource Protocol
.
In method - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
just return needful title.
You can also add delegator on valueChanged
event of UIPickerView
. And each time your value changed you can reload all visible rows and set labels mins and secs at right positions.
Oooor you can just add subview with 2 UILabel
s over the black line.
Oooor you can add subview with black gradient line with labels mins
and secs
.
Then using method : - (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
you can set appropriate width of your columns.
精彩评论