1

我有一个打开的图像,UISlider还有一个箭头图像,一个指向数字 1 2 3 4 5 的拇指图像。默认情况下,滑块位于初始位置,而不是我想要箭头,即拇指图像来自数字 2 并停在 4 不应再往前移动。

当我拖动 thumbImage 时,缩放器(即 1、2、3、4、5)图像被拉伸和压缩,这是不应该发生的。如何解决这个问题?

代码:

UIImage *arrow = [UIImage imageNamed:@"arrow.png"];
UIImage *numbersSlider =  [[UIImage imageNamed:@"numbers_slider(1).png"] stretchableImageWithLeftCapWidth:10 topCapHeight:0];         
sliderPlayers = [[UISlider alloc]initWithFrame:CGRectMake(53.5, 235, 661, 227)];    
[sliderPlayers setThumbImage:arrow forState:UIControlStateNormal];   
[sliderPlayers setBackgroundColor:[UIColor clearColor]];   
[sliderPlayers setMinimumTrackImage:numbersSlider forState:UIControlStateNormal];    
[sliderPlayers setMaximumTrackImage:numbersSlider forState:UIControlStateNormal];    
sliderPlayers.minimumValue = 2.0;    
sliderPlayers.maximumValue = 4.0;
NSLog(@"sliderpalyers %f",sliderPlayers.minimumValue);    
sliderPlayers.continuous = YES;   
sliderPlayers.value = 2.0;    
[sliderPlayers addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];    
[self.view addSubview:sliderPlayers];     

-(void) sliderValueChanged:(id) sender{
    sliderPlayers = (UISlider *) sender;
    [sliderPlayers setValue:(int)(sliderPlayers.value + 0.5f) animated:NO];
    //noOfPlayersTextField.text = [NSString stringWithFormat:@"%d", (int)sliderPlayers.value];
    NSLog(@"slider %d",(int)(sliderPlayers.value + 0.5f));
    numOfPlayers = (int)(sliderPlayers.value + 0.5f);
}

添加图像。在此处输入图像描述

添加了滑块图像:滑块图像

4

1 回答 1

0

像这行代码一样使用。我认为这会对您有所帮助。

Sliderobject.maximumValue=4;
于 2012-05-05T06:41:20.147 回答