How could I make a horizontal picker?

心已入冬 提交于 2019-12-04 15:36:32

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!