为什么不设置此UISlider的value属性更新其位置? [英] Why doesn't setting the value property of this UISlider update its position?
问题描述
... ViewController.h:
...ViewController.h:
@property (nonatomic, strong) IBOutlet UISlider *slider;
... ViewController.m:
...ViewController.m:
@synthesize slider;
- (void)viewDidLoad
{
[super viewDidLoad];
...
currentValue = 50;
self.slider.value = currentValue;
// Do any additional setup after loading the view, typically from a nib.
}
.xib:
我界面中的UISlider连接到滑块属性。
The UISlider in my interface is connected to the slider property.
行为:
滑块全部当它应该在中间时,在价值100的右边的方式。我设置的操作确认currentValue的值为50.如果currentValue为50且slider.value设置为50,为什么位置不反映这个?
The slider sits all the way to the right at value 100 when it is supposed to be in the middle. An action I set up confirms the value of currentValue is 50. If currentValue is 50 and slider.value is set to 50, why doesn't the position reflect this?
PS我尝试了[slider setNeedsDisplay]并且它不会影响这种行为。
P.S. I tried [slider setNeedsDisplay] and it did not affect this behavior.
更新:感谢您的快速解答!多么愚蠢的事情。我在其他地方打印出currentValue为int,所以我现在用以下代码设置slider.value:
Update: thanks for the quick answers! What a silly thing to do. I print out currentValue as an int elsewhere so I am now setting slider.value with this code:
self.slider.value = (float) currentValue/100;
推荐答案
currentValue = 50;
滑块的范围是不 0 ... 100但是0 .. 0.1。你必须写
The slider's range is not 0...100 but 0...1. You have to write either
currentValue = 0.5;
或更改滑块的范围:
self.slider.maximumValue = 100;
这篇关于为什么不设置此UISlider的value属性更新其位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!