UISlider轨迹图像在滑动时消失

时间:2013-02-28 13:57:50

标签: iphone ios uikit uislider

我有这段代码可以创建自定义UISlider。当我快速滑动到最后时,left_image.png没有显示,但如果我不滑动,它可以正常工作。

[sliderFPS setMinimumTrackImage:[UIImage imageNamed:@"left_slider.png"]
                       forState:UIControlStateNormal];
[sliderFPS setMaximumTrackImage:[UIImage imageNamed:@"right_slider.png"]
                       forState:UIControlStateNormal];

[sliderFPS setThumbImage:[UIImage imageNamed:@"thumb_slider.png"]      
                forState:UIControlStateNormal];

我花了2个多小时但找不到任何解决方案。任何帮助都会受到太多赞赏。

1 个答案:

答案 0 :(得分:5)

添加:

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0"))
{
    [[UISlider appearance] setMinimumTrackImage:[[UIImage imageNamed:@"ios6_slider_minimum_value"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 10, 0, 0)] forState:UIControlStateNormal];
    [[UISlider appearance] setMaximumTrackImage:[[UIImage imageNamed:@"ios6_slider_maximum_value"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 10)] forState:UIControlStateNormal];
}
else
{
    [[UISlider appearance] setMinimumTrackImage:[[UIImage imageNamed:@"slider_minimum_value"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 10, 0, 0)] forState:UIControlStateNormal];
    [[UISlider appearance] setMaximumTrackImage:[[UIImage imageNamed:@"slider_maximum_value"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 10, 0, 0)] forState:UIControlStateNormal];
}

[[UISlider appearance] setThumbImage:[UIImage imageNamed:@"slider_button"] forState:UIControlStateNormal];
[[UISlider appearance] setThumbImage:[UIImage imageNamed:@"slider_button"] forState:UIControlStateHighlighted];