问题描述
我有一个UISlider在我的应用程序,我需要有时不仅更新它的值,而且它的minimumValue。值被更改,但如果我调用setValue方法或为我的滑块分配一个新的值,它有新的值,但滑块不会重新绘制到它应该为这个新的值的位置。如何重新绘制?
这是一段我改变minimumValue的代码。
I've an UISlider on my app and I need sometimes to update not only its value but also its minimumValue. The values are changed but if I call the setValue method or assign a new value for my slider, it has the new value but the slider does not repaint itself to the position it should be for this new value. How can I repaint it?This is a piece of code where I change the minimumValue.
if([array count] < 50)
[sliderTamanyo setMinimumValue:2];
else if([array count] < 200)
[sliderTamanyo setMinimumValue:3];
else
[sliderTamanyo setMinimumValue:4];
if(sliderTamanyo.value < sliderTamanyo.minimumValue)
self.sliderTamanyo.value = self.sliderTamanyo.minimumValue;
[self.sliderTamanyo setNeedsDisplay];
推荐答案
我已经解决了,滑块到工具栏。我使用这个代码:
I've solved that by removing and adding again the slider to the toolbar. I've used this code:
NSMutableArray *items = [NSMutableArray arrayWithArray:self.toolbar.items];
id slider = [items lastObject];
[items removeLastObject];
self.toolbar.items = items;
[items addObject:slider];
self.toolbar.items = items;
我已使用 id
代替 UISlider
,因为该滑块位于 UIBarButtonItem
I've recovered my slider using an id
instead an UISlider
because that slider is inside a UIBarButtonItem
这篇关于UISlider不会自动重绘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!