如何添加“结”到 UISlider?

发布于 2024-12-05 09:08:05 字数 158 浏览 0 评论 0原文

我想为 UISlider 上的某些点添加标记。滑块轨道上会出现结。当用户单击结时,滑块值将设置为该值,并且拇指将移动到该点。

我目前已在滑块上添加了图像按钮,但由于 z 位置,拇指在结下方而不是在顶部移动。结应该在轨道上方但在拇指下方。

有谁知道达到这种效果的最佳方法?

I am wanting to add markers for certain points along a UISlider. It will have the appearance of knots on the slider track. When the user clicks on a knot, the slider value is set to that value and the thumb goes to that point.

I have currently added image buttons over the slider, but because of z position the thumb travels under the knots instead of on top. The knots should be over the track but under the thumb.

Does anyone know the best way to achieve this effect?

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

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

发布评论

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

评论(3

弥繁 2024-12-12 09:08:05

我想我已经想出了一个解决方案。使用 2 个 UISlider。将带有自定义轨道图像的原始滑块放下。将其拇指更改为不可见的 PNG。但该滑块顶部的图像按钮。然后添加第二个滑块,其顶部有一条不可见的轨道。这样,轨道来自底部滑块,而拇指来自顶部。

现在,下一个问题:保持这两个 UISlider 同步的最佳方法是什么?科沃? (我以前从未使用过KVO)。

谢谢

I think I have come up with a solution. Use 2 UISliders. Put my original slider with the custom track images down. Change it's thumb to be an invisible PNG. But the image buttons on top of this slider. Then add a 2nd slider with an invisible track on top of that. This way the track comes from the bottom slider while the thumb comes from the top.

Now, next question: how is the best way to keep these 2 UISliders in sync? KVO? (I've never used KVO before).

Thanks

挽袖吟 2024-12-12 09:08:05

假设您已经有了轨道的图像和结的图像,您可以动态组合自定义图像(轨道加上适当定位的结)并将其设置为滑块的轨道图像。这将避免看起来有点老套的双滑块解决方案。

Assuming you already have an image for the track, and an image for the knots, you could compose a custom image on the fly (track plus appropriately positioned knots) and set it to your slider's track image. This would avoid the dual slider solution which seems a bit hacky.

傲世九天 2024-12-12 09:08:05

我能想到的最好的事情是以与您所做的相同的方式创建透明按钮,然后制作一个带有结的自定义滑块轨道。只要结是静态的,您就可以在使用已有的系统的同时,在滑块轨道上产生结的效果。

The best thing that I can think of is creating see through buttons in the same way that you have done, but then making a custom slider track with the knots on it. So long as the knots are static, you can give the effect of having knots on the slider track, while using the system you already have in place.

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