如何获取 UIPickerView 中的分钟和秒如图所示?

发布于 2024-12-03 01:41:14 字数 151 浏览 3 评论 0原文

在此处输入图像描述

我们如何实现这种类型的选定值在 分钟 内更改UIPickerView 中的???

enter image description here

How can we achieve such type of selected values to be changed with mins and secs in UIPickerView???

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

酒几许 2024-12-10 01:41:14

首先,使用 pickerView:viewForRow:inComponent:reusingView: 数据源方法返回“00”标签。这实际上有点棘手,因为 pickerview 会更改此视图的框架以填充行。这意味着您必须将正确定位的视图嵌入到另一个视图中,然后返回该容器视图。

至于标签,这些只是已正确定位并添加为 pickerview 本身的子视图的 UILabel 对象。

为了让它们正确更新,只需在 pickerView:didSelectRow:inComponent: 方法中更改它们的标题即可。

这正是 UIDatePicker 正在做的事情。

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.

枯寂 2024-12-10 01:41:14

您应该实现 UIPickerViewDelegate 协议和 UIPickerViewDataSource 协议。

在方法 - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component 中仅返回所需的标题。

您还可以在 UIPickerViewvalueChanged 事件上添加委托人。每次您的值发生更改时,您都可以重新加载所有可见行并在正确的位置设置标签分钟和秒。

哦,您可以在黑线上添加带有 2 个 UILabel 的子视图。

Oooor 您可以添加带有黑色渐变线和标签 minssecs 的子视图。

然后使用方法: - (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component 您可以设置适当的列宽度。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文