1

I have an image which is on UISlider and also the arrow image a thumbimage which is pointing to the numbers 1 2 3 4 5. By default the slider is being at the intial postion, rather i would like to have the arrow i.e the thumb image from Number 2 and stop at 4 should not move hence forth.

When i am dragging the thumbImage the scaler(i.e 1,2,3,4,5) image is getting stretched and compressed which should not happen. How to solve this?

Code:

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);
}

Added Image.enter image description here

Added Slider image : Slider Image

Cœur
  • 37,241
  • 25
  • 195
  • 267
iYahoo
  • 184
  • 3
  • 16
  • I think you set your image to slider so if your slider move it starch.we ll understand more if you will upload image also.You adjust your image to view only and just move with slider. – vishiphone May 04 '12 at 05:45
  • HI Vishiphone, I have added the image, can u say me know. – iYahoo May 04 '12 at 06:00
  • Thanks,So In this Image which image is starch can you tell me. – vishiphone May 04 '12 at 06:03
  • Hi @vishiphone the image i uploaded is becing streched, sorry for delay as i had no internet connection, for somtime – iYahoo May 04 '12 at 10:00
  • I want your slider perfect image so i find out where you have problem not like that image if you upload then explain this image also the I can able to solve your problem. – vishiphone May 04 '12 at 11:07
  • @vishiphone i added the slider image now the slider image image should start at 2 and end at 4. – iYahoo May 04 '12 at 11:22
  • see: http://stackoverflow.com/questions/2379326/change-iphone-uislider-bar-image – magma May 04 '12 at 11:25
  • 1
    So do one think add your above image on view not on slider because when slider move that image also move and it get starch so do this and tell me what you ll get – vishiphone May 04 '12 at 11:26
  • hey @vishiphone: i tried like that taking the 1st image as the UIimageview and the arrow image as the slider, it is working fine without any compressing and expansion but the problem i am getting is the slider is being visible. – iYahoo May 04 '12 at 12:35
  • So ou also want to hidden the slider id you hidden the slider then your arrow you cant move with slider then you should use scroll view and add that arrow image on that. – vishiphone May 05 '12 at 03:57
  • hey @vishiphone i finally could figure it out like adjusting the width of the image and then now its working fine....got one more problem here as mentioned previuolsy the arrow should start at 2 and end at 4 starting at 2 i had done it, ending at 4 can u help me out with this. – iYahoo May 05 '12 at 06:36
  • @sourishk set the maximum value of slider if you are using if slider. – vishiphone May 05 '12 at 06:39

1 Answers1

0

use like this line of code.I think this will be helpful for you.

Sliderobject.maximumValue=4;
vishiphone
  • 750
  • 7
  • 14
  • I had to keep the maximum value as 5 but it should stop at 4 can it happen? – iYahoo May 05 '12 at 07:04
  • Try Buddy because I dont know about your code it work then its gud for you just try out once if not working then we find other way.. – vishiphone May 05 '12 at 07:07
  • OKay vishiphone, Thank u very much for your kind information and knowledge sharing – iYahoo May 05 '12 at 07:50
  • Your Welcome and if this is helpful for you then please mark the arrow up and mark it right answer so its also helpful for other. – vishiphone May 05 '12 at 08:41