我想知道如何实现类似于iPad默认日历应用程序中的滑块。我已附上下面的图片
如果您在底部看到,它就像一个滑块,允许我们选择任何月份,只需按下它或滑动到它即可。
如果有人能告诉我该控件的名称,那就太好了。我尝试使用 UISlider,但我发现它只允许 3 个选项:
-
setThumbImage
-
setMinimumTrackImage
-
setMaximumTrackImage
如果该控件确实是滑块控件,谁能告诉我我如何插入多个图像/文本
谢谢
I would like to know how to implement the slider similar to the one in the Ipad default calendar application. I have attached the image below
If you see at the bottom, it acts like a slider which allows us to select any month either by just pressing it or sliding to it.
It would be great if anyone could tell me the name of that control. I tried using UISlider but I see that it allows only 3 options:
setThumbImage
setMinimumTrackImage
setMaximumTrackImage
If that control is indeed a slider control, could anyone tell me how I would be able to insert multiple images/ text
Thanks
发布评论
评论(2)
它可能比您想要的更复杂,但您可以自己制作:
制作一个具有日期 UILabels 的背景
制作一个选择框
在 UIViewController 中您可以放置诸如以下内容:
touchesMoved -
使选择框的x值等于触摸
touchesEnded -
使选择框的 x 值等于触摸的最后一个 x 值。
移动的触摸将允许拖动选择框,touchesEnded 将允许点击选择。
然后,您只需将选择框设置为 x 值的动画即可。
(这是一个极其简化的版本,但您可以很容易地做到这一点。)
It may be more complex than you'd like, but you could make your own:
Make a background that has UILabels for the dates
Make a selection box
In the UIViewController you could put something such as:
touchesMoved -
Make the selection box's x value equal to the touch
touchesEnded -
Make the selection box's x value equal to the touch's last x value
The touches moved would allow dragging of the selection box, and the touchesEnded would allow tap selection.
Then you would simply animate the selection box to the x value.
(This is an extremely simplified version, but you could do this pretty easily.)
这可以通过使用 UIScrollView 来实现。根据您的要求以编程方式添加具有背景图像和文本的 UIButton。
您可以参考 教程1 教程2 其中屏幕上仅显示 1 页(图像)。您需要进行一些计算以应用相同的逻辑来满足您的要求。即您的滚动视图将如图像中显示的那样更小(高度)和更大(宽度),尽管有图像,您仍将添加 UIButtons,最重要的是一次显示超过 1 个项目,但这并不困难。主要部分只是以编程方式滚动。
This can be achieved by using UIScrollView. Add UIButtons programmatically having background images and text as well on them as per your requirement.
You can refer tutorial1 tutorial2 in which on screen only 1 page(Image) is displayed. You need to do some calculation for applying same logic to fit your requirement. i.e. Your scrollview will be smaller(in height) and bigger(in width) as displayed in image, you will be adding UIButtons in spite of images and most important at a time displaying more than 1 item but it won't be difficult. The Main part is only programmatically scrolling.