UISlider上的UIImage正在被拉伸

时间:2012-05-04 05:19:38

标签: ios cocoa-touch uiimage uislider

我有一个图像在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);
}

添加了图片。enter image description here

添加了滑块图片:Slider Image

1 个答案:

答案 0 :(得分:0)

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

Sliderobject.maximumValue=4;