我怎样才能制作一个水平选择器?

发布于 2024-10-10 03:56:32 字数 65 浏览 0 评论 0原文

我想为我的应用程序制作一个水平选择器,但我对这一切还很陌生。有人可以提供一个易于遵循的指南来指导我如何做到这一点吗?

I want to make a horizontal picker for my app, but I'm kinda new at all this. Could someone provide an easy to follow guide on how I'd make this?

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

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

发布评论

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

评论(2

鼻尖触碰 2024-10-17 03:56:32

最好的方法是使用启用分页的 UIScrollView 来伪造您自己的。实际上相当简单,将滚动视图与您自己的自定义图形视图重叠。

The best way is to fake your own using UIScrollView with pagination enabled. It's actually fairly easy, overlaying a scroll view with your own views for custom graphics.

小梨窩很甜 2024-10-17 03:56:32

适用于 iOS 的开源水平选择器组件刚刚在 GitHub 上发布。

可以按如下方式将其添加到 UITableViewCell(在 tableView:cellForRowAtIndexPath: 中):

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
STHorizontalPicker *horizontalPickerView = [[STHorizontalPicker alloc] initWithFrame:cell.frame];
horizontalPickerView.name = @"myPicker";
[horizontalPickerView setMinimumValue:0.0];
[horizontalPickerView setMaximumValue:100.0];
[horizontalPickerView setSteps:100];
[horizontalPickerView setDelegate:self];
[horizontalPickerView setValue:50.0];

无论如何,它都不具备 UIPickerView 的所有功能,但它说明了实现控件的一种可能方法(一个 UIScrollView 包含一个带有多个用于标记的 CATextLayers 的 UIView),并且有一些不错的功能,例如捕捉到标记。

An open-source horizontal picker component for iOS has just been released on GitHub.

It can be added to a UITableViewCell as follows (in tableView:cellForRowAtIndexPath:):

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
STHorizontalPicker *horizontalPickerView = [[STHorizontalPicker alloc] initWithFrame:cell.frame];
horizontalPickerView.name = @"myPicker";
[horizontalPickerView setMinimumValue:0.0];
[horizontalPickerView setMaximumValue:100.0];
[horizontalPickerView setSteps:100];
[horizontalPickerView setDelegate:self];
[horizontalPickerView setValue:50.0];

It doesn't have all of the features of a UIPickerView by any means, but it illustrates one possible way to implement a control (a UIScrollView containing a UIView with multiple CATextLayers for the markers) and has a couple of nice features like snapping to markers.

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