UISlider 在 iOS 5 中缺少轨道图像

发布于 2024-12-19 09:58:52 字数 561 浏览 1 评论 0原文

我有一个 UISlider,我使用以下代码设置了自定义 trackImages 和thumbImage:

[progress setMinimumTrackImage:[UIImage imageNamed:@"scrubbar-inactive.png"] forState:UIControlStateNormal];
[progress setMaximumTrackImage:[UIImage imageNamed:@"scrubbar-active.png"] forState:UIControlStateNormal];
[progress setThumbImage:[UIImage imageNamed:@"scrubbar-ball.png"] forState:UIControlStateNormal];
[progress setThumbImage:[UIImage imageNamed:@"scrubbar-ball.png"] forState:UIControlStateHighlighted];

一切正常,但在 iOS 5 中我很少只得到thumbImage 而没有下面的trackImages。

I have a UISlider, and I set custom trackImages and thumbImage, using the following code:

[progress setMinimumTrackImage:[UIImage imageNamed:@"scrubbar-inactive.png"] forState:UIControlStateNormal];
[progress setMaximumTrackImage:[UIImage imageNamed:@"scrubbar-active.png"] forState:UIControlStateNormal];
[progress setThumbImage:[UIImage imageNamed:@"scrubbar-ball.png"] forState:UIControlStateNormal];
[progress setThumbImage:[UIImage imageNamed:@"scrubbar-ball.png"] forState:UIControlStateHighlighted];

Everything works fine, but in iOS 5 infrequently I get only the thumbImage and no trackImages underneath.

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

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

发布评论

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

评论(2

本王不退位尔等都是臣 2024-12-26 09:58:52

我确信您正在更新计时器中的 progress.value 而不是检查 NaN 值。
只需以这种方式添加对 NaN 的检查:

//a necessary value for a slider
NSTimeInterval sliderPosition = ...;

if (sliderPosition != sliderPosition)
    return;    //NaN detected
else
    [progress setValue:sliderPosition animated:NO];

还有一个名为 NAN 的常量,但它对我不起作用。

I'm sure you're updating progress.value in a timer and not checking for NaN values.
Just add a checking for NaN this way:

//a necessary value for a slider
NSTimeInterval sliderPosition = ...;

if (sliderPosition != sliderPosition)
    return;    //NaN detected
else
    [progress setValue:sliderPosition animated:NO];

There is also a constant called NAN, but it didn't work for me.

月下凄凉 2024-12-26 09:58:52

我之前遇到过类似的问题,轨道图像在 iOS 4 中总是显示正常,但在 iOS 5 中却不行。我尝试调整图像大小。这对我有用。请尝试这个:

UIImage *leftTrackImage = [[UIImage imageNamed:@"progress_left.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
UIImage *rightTrackImage = [[UIImage imageNamed:@"progress_right.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 0)];

I had similar problem before where the track images always show up okay in iOS 4 but not in iOS 5. I tried to make the images resizable. And it worked for me. Please try this:

UIImage *leftTrackImage = [[UIImage imageNamed:@"progress_left.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
UIImage *rightTrackImage = [[UIImage imageNamed:@"progress_right.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文