开发者

How to get the mins and secs in UIPickerView as in figure?

开发者 https://www.devze.com 2023-04-01 19:45 出处:网络
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 meth

How to get the mins and secs in UIPickerView as in figure?

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 UILabels 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消