…ViewController.h:
@property (nonatomic, strong) IBOutlet UISlider *slider;
…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:
The UISlider in my interface is connected to the slider property.
Behavior:
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?
P.S. I tried [slider setNeedsDisplay] and it did not affect this behavior.
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;
The slider’s range is not 0…100 but 0…1. You have to write either
or change the range of the slider: