Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there a way to move my imageview with the move of the slider thumb?
    text
    copied!<p>I want to move my imageview as user slide the thumb of UISlider and the image view should also have the value of the slider. Does any one have any idea about this?? Here's the code snippets:</p> <pre><code> -(void)addSliderX:frame andminimumValue:(int)min andmaximumValue:(int)max andSliderValue:(int)value{ CGRect frame1 = CGRectFromString(frame); statSlider = [[UISlider alloc]initWithFrame:frame1]; [statSlider setMinimumTrackImage:[[UIImage imageNamed:@"greenSlider.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:10.0] forState:UIControlStateNormal]; [statSlider setThumbImage:[UIImage imageNamed:@"sliderBar_greenThumb.png"] forState:UIControlStateNormal]; [statSlider setMinimumValue:min]; [statSlider setMaximumValue:max]; statSlider.continuous = YES; [statSlider addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged]; [statSlider addTarget:self action:@selector(sliderChanged:) forControlEvents:UIControlEventTouchUpInside]; //bubbleViewController = [[SFNDoorBubbleViewController alloc]initWithNibName:@"SFNDoorBubbleViewController"bundle:[NSBundle mainBundle]]; //popoverController = [[UIPopoverController alloc] initWithContentViewController:bubbleViewController]; //[popoverController setPopoverContentSize:bubbleViewController.view.frame.size]; [self.view addSubview:statSlider]; } -(void)valueChanged:(id)sender{ UISlider *localSlider = (UISlider *)sender; bubble = [[UIView alloc]init]; back = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"sliderBar_handle_number.png"]]; greenSliderValue = [[NSString alloc] initWithString:[NSString stringWithFormat:@"%3.0f", [localSlider value]]]; UILabel * val = [[UILabel alloc]init]; dsp =[greenSliderValue floatValue]; val.text = greenSliderValue; [bubbleViewController updateSliderValueTo:dsp]; CGFloat sliderMax = localSlider.maximumValue; CGFloat sliderMin = localSlider.minimumValue; CGFloat sliderMaxMinDiff = sliderMax - sliderMin; CGFloat sliderValue = dsp; if(sliderMin &lt; 0.0) { sliderValue = dsp-sliderMin; sliderMax = sliderMax - sliderMin; sliderMin = 0.0; sliderMaxMinDiff = sliderMax - sliderMin; } CGFloat xCoord = ((sliderValue-sliderMin)/sliderMaxMinDiff)*[localSlider frame].size.width-bubbleViewController.view.frame.size.width/2.0; CGFloat halfMax = (sliderMax+sliderMin)/2.0; if(sliderValue &gt; halfMax) { sliderValue = (sliderValue - halfMax)+(sliderMin*1.0); sliderValue = sliderValue/halfMax; sliderValue = sliderValue*11.0; xCoord = xCoord - sliderValue; } else if(sliderValue &lt; halfMax) { sliderValue = (halfMax - sliderValue)+(sliderMin*1.0); sliderValue = sliderValue/halfMax; sliderValue = sliderValue*11.0; xCoord = xCoord + sliderValue; } [self.view addSubview:bubble]; [bubble addSubview:back]; [bubble addSubview:val]; bubble.frame = CGRectMake(xCoord, 500, bubbleViewController.view.frame.size.width, bubbleViewController.view.frame.size.height); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload