0

我有这段代码可以创建自定义 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];

我花了两个多小时,但找不到任何解决方案。任何帮助将不胜感激。

4

1 回答 1

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];
于 2013-02-28T14:08:34.807 回答