我有一个带有minValue = 0和maximumValue = 1000的滑块。我在滑块上有一个气泡,它用滑块的拇指运行并显示滑块的值。 但是我无法用滑块拇指运行气泡。 这是代码片段:
CGFloat sliderMax = localSlider.maximumValue;
CGFloat sliderMin = localSlider.minimumValue;
CGFloat sliderMaxMinDiff = sliderMax - sliderMin;
CGFloat sliderValue = _dsp;
CGFloat halfMax = (sliderMax+sliderMin)/2.0;
//int hMax = [halfMax intValue];
CGFloat xCoord = halfMax- 55.0;
CGFloat yCoord = (CGFloat)_positionX;
if (sliderValue > halfMax)
{
xCoord = xCoord-(sliderValue-halfMax);
}
else
{
xCoord = xCoord + (halfMax-sliderValue);
}
xCoord= xCoord + (642/sliderMaxMinDiff)*(sliderValue-sliderMin);
newB.frame = CGRectMake(xCoord,yCoord,84,47);
答案 0 :(得分:0)
@Ashutosh它可能有些用处
-(void)sliderValueChanged:(id)sender{
UISlider *slider = (UISlider*)sender;
CGFloat sliderMin = slider.minimumValue;
CGFloat sliderMax = slider.maximumValue;
CGFloat sliderMaxMinDiff = sliderMax - sliderMin;
CGFloat sliderValue = slider.value;
if(sliderMin < 0.0) {
sliderValue = slider.value-sliderMin;
sliderMax = sliderMax - sliderMin;
sliderMin = 0.0;
sliderMaxMinDiff = sliderMax - sliderMin;
}
CGFloat xCoord = ((sliderValue-sliderMin)/sliderMaxMinDiff)*[slider frame].size.width-SLIDER_CALLOUT_WIDTH/2.0;
CGFloat halfMax = (sliderMax+sliderMin)/2.0;
if(sliderValue > halfMax) {
sliderValue = (sliderValue - halfMax)+(sliderMin*1.0);
sliderValue = sliderValue/halfMax;
sliderValue = sliderValue*11.0;
xCoord = xCoord - sliderValue;
}
else if(sliderValue < halfMax) {
sliderValue = (halfMax - sliderValue)+(sliderMin*1.0);
sliderValue = sliderValue/halfMax;
sliderValue = sliderValue*11.0;
xCoord = xCoord + sliderValue;
}
int index = ceil(slider.value) ;
if (MIN_INDEX<= index <=MAX_INDEX) {
CGPoint callOutPoint = CGPointMake(xCoord, slider.frame.origin.y);
//[self drawCallOutAtRect:callOutPoint andDate:[self.dataSourceArray objectAtIndex:(8-index)]];
//Call A Function To draw Bubble on Slider Top
}
previousIndex = index;
}
您也可以从https://github.com/elc/ELCSlider
中获取一些提示以下是我制作
的屏幕截图我使用这些值添加了滑块 -
UISlider *timeSliderObj = [[UISlider alloc] initWithFrame:CGRectMake(0, 0, 280, 44)];
timeSliderObj.maximumValue = 8;
timeSliderObj.minimumValue = 1;
timeSliderObj.value = 8;