How could I make a horizontal picker?

喜夏-厌秋 提交于 2019-12-06 11:32:00

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/4594685/how-could-i-make-a-horizontal-picker

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