自定义滑块轨道图像

发布于 2024-12-08 10:47:30 字数 124 浏览 0 评论 0原文

您好,我想自定义我的 UISlider,类似于 iBooks 的方式。我知道 [滑块 setMaximumTrackImage:] 和 [滑块 setMinimumTrackImage:] 但是有人可以澄清我在图像中需要多少个点吗?

Hi i would like to customize my UISlider similar to the way iBooks has done. I Know that
[slider setMaximumTrackImage:] and [slider setMinimumTrackImage:]
are to be used.But can someone clarify as to how many dots would i need in the image?

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

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

发布评论

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

评论(1

白鸥掠海 2024-12-15 10:47:30

图像应该是可拉伸的。来自文档

轨道图像的方向必须与轨道图像的方向相匹配
滑块控制。为了便于拉伸图像以填充
拇指和终点之间的空间,轨迹图像通常是
定义为三个区域。可拉伸区域位于两端之间
上限区域。端盖定义了图像中保留的部分
按原样并且没有拉伸。可拉伸区域的宽度为 1 点
端盖之间的区域可以复制以制作图像
显得更长。

要定义水平滑块的端盖尺寸,请为图像的 leftCapWidth 属性指定适当的值。有关此值如何定义滑块区域的更多信息,请参阅 UIImage 类。

因此,您绘制的图像将具有结束部分(默认滑块中最左侧的圆形部分) - 其宽度由左大写宽度定义。然后是一个 1 像素宽的部分,可以拉伸到滑块的长度,然后是右盖(占据图像的剩余部分)。

理论上,您可以制作一个一像素宽的图像,并且该图像只会从轨道末端拉伸到当前拇指位置。然而,这最终没有任何形状。

The images are supposed to be stretchable. From the docs:

The orientation of the track image must match the orientation of the
slider control. To facilitate the stretching of the image to fill the
space between the thumb and end point, track images are usually
defined in three regions. A stretchable region sits between two end
cap regions. The end caps define the portions of the image that remain
as is and are not stretched. The stretchable region is a 1-point wide
area between the end caps that can be replicated to make the image
appear longer.

To define the end cap sizes for a horizontally-oriented slider, assign an appropriate value to the image’s leftCapWidth property. For more information about how this value defines the regions of the slider, see the UIImage class.

So, the image you draw would have your end part (the rounded part on the far left in the default slider) - the width of this is defined by your left cap width. Then a 1-pixel wide part which can be stretched to the length of the slider, then a right cap (which takes up the remaining part of the image).

In theory then you could make a one-pixel wide image and this would just be stretched out from the end of the track to the current thumb position. However, this would have no shape at the end.

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